SimpleContainer - Possibility to register constructor?

Aug 9, 2010 at 3:14 PM
Edited Aug 9, 2010 at 3:41 PM

Hi Rob,

I've been struggling to get FormsAuthentication working in SL with Caliburn.Micro but now I have my own little AuthenticationService :). My problem now is that I wanted to to this

    public class ShellViewModel : Conductor<IScreen>.Collection.OneActive, IShell
    {
        Func<AuthenticationServiceClient> createAuthProxy;
        private AuthenticationServiceClient proxy;
        public ShellViewModel(Func<AuthenticationServiceClient> createAuthProxy)
        {
            this.createAuthProxy = createAuthProxy;
            proxy = createAuthProxy();
        }
Since the SimpleContainer is constructor greedy and selects the one with most parameters it doesn't work :(. (And you get several constructors auto-generated)
Do you think it would be possible to somehow tell the SimpleContainer that it should use it's default constructor?
/Christoffer
EDIT - I added a function in SimpleContainer that uses the DefaultCtor
        public void RegisterPerRequestWithDefaultCtor(Type service, string key, Type implementation)
        {
            RegisterHandler(service, key, () => BuildInstanceWithDefaultCtor(implementation));
        }
        object BuildInstanceWithDefaultCtor(Type type)
        {
            var args = new List<object>();
            return ActivateInstance(type, args.ToArray());
        }
worked! :)
Coordinator
Aug 9, 2010 at 3:42 PM
Try using the RegisterHandler method to provide your own custom resolution strategy. That's the best I can do with the SimpleContainer.