Castle Windsor - Nested Runtime Dependencies

I am using the Castle Windosr container. I want to be able to specify some constructor dependencies at runtime, which can obviously be done with the Resolve overload that accepts a dictionary, all well and good. However, if I want to specify the runtime dependency on the root dependencies then I am at a loss, for the moment I was working by explicitly creating each and injecting it. This is essentially a decorator script, and I want to get an instance of the decorator, providing a runtime dependency for the object under decoration. Any ideas? I would rather not do what I am doing below, and I would prefer that the decarator constructor does not fill the object underneath as there will be times when the dependencies do not match.

   public static IActivity GetActivityFromIoC(string key, Message message, Audit audit)
        {

            IActivity activity = IoC.Resolve<IActivity>(key, new Dictionary<
                                                                              string, object>(){
                { "message", message }
                });

            IActivity auditingActivity = IoC.Resolve<IActivity>("auditing.activity", new Dictionary<
                                                                              string, object>(){
            { "activity", activity },     
            { "message", message },
            { "audit", audit }

                });

            return auditingActivity;

        }

      

+1


source to share


1 answer


You can probably handle this by writing your own ISubDependencyResolver that does it for you. Only the container does not allow this, and most likely it will never do it. What for? The short answer is that you are making assumptions about your component dependencies that are not-no and a container - all about removing this type of knowledge from the caller.



+1


source







All Articles