示例#1
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
            }
        }
示例#2
0
        public WindsorUseCase()
        {
            container = new WindsorContainer();

            Register <IWebService, WebService>();
            Register <IAuthenticator, Authenticator>();
            Register <IStockQuote, StockQuote>();
            Register <IDatabase, Database>();
            Register <IErrorHandler, ErrorHandler>();

            container.AddComponentWithLifestyle <ILogger, Logger>(LifestyleType.Singleton);

            Register <ILogger, Logger>();
        }
示例#3
0
 public static void RegisterTransient <TFacility>(string key, Type implementation)
 {
     _container.AddComponentWithLifestyle(key, typeof(TFacility), implementation, LifestyleType.Transient);
 }
示例#4
0
 public void Register <T, R>()
 {
     container.AddComponentWithLifestyle(typeof(T).Name, typeof(T), typeof(R), LifestyleType.Transient);
 }