Beispiel #1
0
        protected override void AddDependencyInstanceCore(Type serviceType, object instance, DependencyLifetime lifetime)
        {
            var key = GetComponentName(serviceType);

            lock (ContainerLock)
            {
                if (lifetime == DependencyLifetime.PerRequest)
                {
                    // try to see if we have a registration already
                    if (!_windsorContainer.Kernel.HasComponent(serviceType))
                    {
                        // if there's already an instance registration we update the store with the correct reg.
                        _windsorContainer.Register(Component
                                                   .For(serviceType)
                                                   .Named(key)
                                                   .UsingFactoryMethod(kernel => kernel.Resolve <ScopedInstanceStore>().GetInstance(serviceType))
                                                   .LifestyleScoped());
                    }

                    _windsorContainer.Resolve <ScopedInstanceStore>().SetInstance(serviceType, instance);
                }
                else
                {
                    _windsorContainer.Register(Component
                                               .For(serviceType)
                                               .Instance(instance)
                                               .Named(key)
                                               .IsDefault()
                                               .LifeStyle.Is(ConvertLifestyles.ToLifestyleType(lifetime)));
                }
            }
        }
Beispiel #2
0
        protected override void AddDependencyCore(Type dependent, Type concrete, DependencyLifetime lifetime)
        {
            string componentName = Guid.NewGuid().ToString();

            if (lifetime != DependencyLifetime.PerRequest)
            {
#if CASTLE_20
                _windsorContainer.AddComponentLifeStyle(componentName, dependent, concrete,
                                                        ConvertLifestyles.ToLifestyleType(lifetime));
#elif CASTLE_10
                _windsorContainer.AddComponentWithLifestyle(componentName, dependent, concrete, ConvertLifestyles.ToLifestyleType(lifetime));
#endif
            }
            else
            {
#if CASTLE_20
                _windsorContainer.Register(
                    Component.For(dependent).Named(componentName).ImplementedBy(concrete).LifeStyle.Custom(typeof(ContextStoreLifetime)));
#elif CASTLE_10
                ComponentModel component = _windsorContainer.Kernel.ComponentModelBuilder.BuildModel(componentName, dependent, concrete, null);
                component.LifestyleType   = ConvertLifestyles.ToLifestyleType(lifetime);
                component.CustomLifestyle = typeof(ContextStoreLifetime);
                _windsorContainer.Kernel.AddCustomComponent(component);
#endif
            }
        }
Beispiel #3
0
        protected override void AddDependencyCore(Type dependent, Type concrete, DependencyLifetime lifetime)
        {
            string componentName = GetComponentName(dependent);

            lock (ContainerLock)
            {
                _windsorContainer.Register(Component.For(dependent).ImplementedBy(concrete).Named(componentName).LifeStyle
                                           .Is(ConvertLifestyles.ToLifestyleType(lifetime)));
            }
        }
Beispiel #4
0
 public void Register(string componentName, IWindsorContainer container, DependencyFactoryModel registration)
 {
     if (registration.Factory == null)
     {
         container.Register(Component
                            .For <TService>()
                            .Named(componentName)
                            .ImplementedBy <TConcrete>()
                            .LifeStyle.Is(ConvertLifestyles.ToLifestyleType(registration.Lifetime)));
     }
     else
     {
         var factoryMethod = ((Expression <Func <TConcrete> >)registration.Factory).Compile();
         container.Register(
             Component.For <TService>()
             .Named(componentName)
             .UsingFactoryMethod(factoryMethod)
             .LifeStyle.Is(ConvertLifestyles.ToLifestyleType(registration.Lifetime)));
     }
 }
Beispiel #5
0
        protected override void AddDependencyCore(Type dependent, Type concrete, DependencyLifetime lifetime)
        {
            string componentName = Guid.NewGuid().ToString();

            lock (ContainerLock)
            {
                if (lifetime != DependencyLifetime.PerRequest)
                {
                    _windsorContainer.Register(Component.For(dependent).ImplementedBy(concrete).Named(componentName).LifeStyle.Is(ConvertLifestyles.ToLifestyleType(lifetime)));
                }
                else
                {
                    _windsorContainer.Register(Component.For(dependent).Named(componentName).ImplementedBy(concrete).LifeStyle.Custom(typeof(ContextStoreLifetime)));
                }
            }
        }