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 } }
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>(); }
public static void RegisterTransient <TFacility>(string key, Type implementation) { _container.AddComponentWithLifestyle(key, typeof(TFacility), implementation, LifestyleType.Transient); }
public void Register <T, R>() { container.AddComponentWithLifestyle(typeof(T).Name, typeof(T), typeof(R), LifestyleType.Transient); }