Exemplo n.º 1
0
        public void Configure(Type component, DependencyLifecycle dependencyLifecycle)
        {
            this.ThrowIfDisposed();
            lock (this.configuredInstances)
            {
                if (this.configuredInstances.ContainsKey(component))
                {
                    return;
                }
            }
            ILifecycle         lifecycle          = NServiceBusStructureMapObjectBuilder.GetLifecycleFrom(dependencyLifecycle);
            ConfiguredInstance configuredInstance = null;

            this.container.Configure(delegate(ConfigurationExpression x)
            {
                configuredInstance = x.For(component, null).LifecycleIs(lifecycle).Use(component);
                x.EnableSetterInjectionFor(component);
                List <Type> list = NServiceBusStructureMapObjectBuilder.GetAllInterfacesImplementedBy(component).ToList <Type>();
                foreach (Type current in list)
                {
                    x.For(current, null).LifecycleIs(lifecycle).Use((IContext c) => c.GetInstance(component));
                    x.EnableSetterInjectionFor(current);
                }
            });
            lock (this.configuredInstances)
            {
                this.configuredInstances.Add(component, configuredInstance);
            }
        }
Exemplo n.º 2
0
        public void Configure <T>(Func <T> componentFactory, DependencyLifecycle dependencyLifecycle)
        {
            this.ThrowIfDisposed();
            Type pluginType = typeof(T);

            lock (this.configuredInstances)
            {
                if (this.configuredInstances.ContainsKey(pluginType))
                {
                    return;
                }
            }
            ILifecycle            lifecycle      = NServiceBusStructureMapObjectBuilder.GetLifecycleFrom(dependencyLifecycle);
            LambdaInstance <T, T> lambdaInstance = null;

            this.container.Configure(delegate(ConfigurationExpression x)
            {
                lambdaInstance = x.For <T>(null).LifecycleIs(lifecycle).Use <T>("Custom constructor func", componentFactory);
                x.EnableSetterInjectionFor(pluginType);
                foreach (Type current in NServiceBusStructureMapObjectBuilder.GetAllInterfacesImplementedBy(pluginType))
                {
                    x.For(current, null).Use((IContext c) => (object)c.GetInstance <T>());
                    x.EnableSetterInjectionFor(current);
                }
            });
            lock (this.configuredInstances)
            {
                this.configuredInstances.Add(pluginType, lambdaInstance);
            }
        }