public void RegisterMultipleAssemblyTypes_BasedOn_RegisteredInContainer() { Kernel.Register( AllTypes.FromAssembly(Assembly.GetExecutingAssembly()) .BasedOn <ICommon>() .BasedOn <ICustomer>() .If(t => t.FullName.Contains("Chain")) .BasedOn <DefaultTemplateEngine>() .BasedOn <DefaultMailSenderService>() .BasedOn <DefaultSpamServiceWithConstructor>() ); var handlers = Kernel.GetHandlers(typeof(ICommon)); Assert.AreEqual(0, handlers.Length); handlers = Kernel.GetAssignableHandlers(typeof(ICommon)); Assert.AreNotEqual(0, handlers.Length); handlers = Kernel.GetAssignableHandlers(typeof(ICustomer)); Assert.AreNotEqual(0, handlers.Length); foreach (var handler in handlers) { Assert.IsTrue(handler.ComponentModel.Implementation.FullName.Contains("Chain")); } handlers = Kernel.GetAssignableHandlers(typeof(DefaultSpamServiceWithConstructor)); Assert.AreEqual(1, handlers.Length); }
/// <summary> /// Instantiate the container and add all Controllers that derive from /// WindsorController to the container. Also associate the Controller /// with the WindsorContainer ControllerFactory. /// </summary> protected virtual void InitializeServiceLocator() { var container = new WindsorContainer(); // Initialize MVC application ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container)); container.RegisterControllers(typeof(HomeController).Assembly); ComponentRegistrar.AddComponentsTo(container); // Initialize WebApi container.Register(AllTypes.FromAssembly(typeof(HomeController).Assembly) .BasedOn <ApiController>() .If(r => r.Name.EndsWith("Controller")) .LifestyleTransient()); GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator), new WindsorCompositionRoot(container)); GlobalConfiguration.Configuration.DependencyResolver = new WindsorDependencyResolver(container); // Setup service locator var windsorServiceLocator = new WindsorServiceLocator(container); DomainEvents.ServiceLocator = windsorServiceLocator; ServiceLocator.SetLocatorProvider(() => windsorServiceLocator); }
public override void Install(IWindsorContainer container, IConfigurationStore store) { base.Install(container, store); container.Register(AllTypes.FromAssembly(Assembly.GetExecutingAssembly()) .BasedOn <IHttpController>() .LifestyleTransient()); container.Register(Component.For <IErrorditeService>() .ImplementedBy(typeof(ErrorditeService)) .LifestyleSingleton()); container.Register(Component.For <IHttpControllerActivator>() .Instance(new WindsorHttpControllerActivator()) .LifestyleSingleton()); container.Register(Component.For <IMessageProcessor>() .ImplementedBy(typeof(SQSMessageProcessor)) .LifestyleTransient()); container.Register(Component.For <IRequestThrottler>() .ImplementedBy(typeof(SQSRequestThrottler)) .LifestyleTransient()); container.Register(Component.For <IQueueProcessor>() .ImplementedBy(typeof(SQSQueueProcessor)) .LifestyleTransient()); container.Register(Classes.FromAssembly(Assembly.GetExecutingAssembly()) .BasedOn(typeof(IErrorditeConsumer <>)) .WithServiceFromInterface(typeof(IErrorditeConsumer <>)) .LifestyleTransient()); }
/// <summary> /// Installs the assemblies. /// </summary> /// <param name = "container">The container.</param> /// <param name = "assemblies">The assemblies.</param> public static void InstallAssemblies(this IIoCContainer container, Assembly[] assemblies) { //Contract.Requires(container != null); //Contract.Requires(assemblies != null); using (var registrationContainer = new WindsorContainer()) { foreach (var assembly in assemblies) { try { //container.Install(FromAssembly.Instance(assembly)); registrationContainer.Register(AllTypes.FromAssembly(assembly) .IncludeNonPublicTypes() .BasedOnAsService <IComponentInstaller>() .Configure(c => c.LifeStyle.Transient)); } catch (Exception e) { var msg = String.Format("Could not load assembly '{0}' because related assembly can't be loaded. Exception details: {1}", assembly.FullName, e.Message); _logger.Fatal(msg, e); throw new Exception(msg); } } foreach (var item in registrationContainer.ResolveAll <IComponentInstaller>()) { item.Install(container, assemblies); } } }
public static void RegisterAllConfigurationsIn(this IWindsorContainer container, IEnumerable <Assembly> assemblies) { foreach (var assembly in assemblies) { container.Register(AllTypes.FromAssembly(assembly).BasedOn <IConfigureMapping>().WithService.Select(new[] { typeof(IConfigureMapping) }).Configure(c => c.LifeStyle.Transient)); } }
public IRegistration IsAppropriate(Type repositoryServiceType, string inNamespace, string endsWith) { return(AllTypes.FromAssembly(assembly) .Where(IsAppropriateDelegate(repositoryServiceType, inNamespace, endsWith)) .WithService.Select(SelectService(repositoryServiceType)) .Configure(new ConfigureDelegate(ConfigureRegistration))); }
public static IKernel Install() { var container = Container; container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel)); container.Install(new ProcessingBasicInstaller()); RegisterManagers(container); container.Register( AllTypes.FromAssembly(typeof(Gateway.NuGet.Core.AttributeRouting).Assembly) .BasedOn <IController>() .LifestyleTransient() ); container.Register( AllTypes.FromAssembly(typeof(Gateway.WinDbg.Core.AttributeRouting).Assembly) .BasedOn <IController>() .LifestyleTransient() ); container.Register( AllTypes.FromThisAssembly() .BasedOn <IController>() .LifestyleTransient() ); ControllerBuilder.Current.SetControllerFactory(new MCControllerFactory(container.Kernel)); ServiceLocator.Locator = new SimpleServiceLocator(container.Resolve); return(container.Kernel); }
public void RegisterAssemblyTypes_WithConfigurationBasedOnImplementation_RegisteredInContainer() { Kernel.Register(AllTypes.FromAssembly(Assembly.GetExecutingAssembly()) .BasedOn <ICommon>() .Configure(delegate(ComponentRegistration component) { component.LifeStyle.Transient .Named(component.Implementation.FullName + "XYZ"); }) .ConfigureFor <CommonImpl1>( component => component.DependsOn(Property.ForKey("key1").Eq(1))) .ConfigureFor <CommonImpl2>( component => component.DependsOn(Property.ForKey("key2").Eq(2))) ); foreach (var handler in Kernel.GetAssignableHandlers(typeof(ICommon))) { Assert.AreEqual(LifestyleType.Transient, handler.ComponentModel.LifestyleType); Assert.AreEqual(handler.ComponentModel.Implementation.FullName + "XYZ", handler.ComponentModel.Name); if (handler.ComponentModel.Implementation == typeof(CommonImpl1)) { Assert.AreEqual(1, handler.ComponentModel.CustomDependencies.Count); Assert.IsTrue(handler.ComponentModel.CustomDependencies.Contains("key1")); } else if (handler.ComponentModel.Implementation == typeof(CommonImpl2)) { Assert.AreEqual(1, handler.ComponentModel.CustomDependencies.Count); Assert.IsTrue(handler.ComponentModel.CustomDependencies.Contains("key2")); } } }
public static void RegisterAllGlobalConventionsIn(this IWindsorContainer container, IEnumerable <Assembly> assemblies) { foreach (var assembly in assemblies) { container.Register(AllTypes.FromAssembly(assembly).BasedOn <IConfigureGlobalConventions>().WithService.Base().Configure(c => c.LifeStyle.Transient)); } }
protected void Application_Start() { Container = new WindsorContainer(); // Common Service Locator ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(Container)); // RavenDB embedded Container.Register(Component .For <IDocumentStore>() .UsingFactoryMethod(() => GetDocumentStore()) .LifeStyle.Singleton); // MVC components ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(Container)); Container.Register(AllTypes .FromAssembly(Assembly.GetExecutingAssembly()) .BasedOn <IController>() .Configure(c => c.LifeStyle.Transient) ); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); }
public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register( AllTypes.FromAssembly(typeof(MvcApplication).Assembly) .BasedOn <Hub>().Configure( x => x.Named(x.Implementation.FullName.ToLower()).LifeStyle.Transient)); }
protected virtual void ConfigureContainer() { container.Register( AllTypes.Of <IController>() .FromAssembly(Assembly) .Configure(registration => { var name = registration.Implementation.Name; registration.Named(name.Replace("Controller", "").ToLowerInvariant()); }), AllTypes.Of <IController>() .FromAssembly(typeof(AbstractBootStrapper).Assembly) .Configure(registration => { var name = registration.Implementation.Name; registration.Named(name.Replace("Controller", "").ToLowerInvariant()); }), AllTypes.FromAssembly(Assembly) .Where(x => x.Namespace.EndsWith("Services")) .WithService.FirstInterface(), AllTypes.FromAssembly(typeof(AbstractBootStrapper).Assembly) .Where(x => x.Namespace.EndsWith("Services")) .WithService.FirstInterface() ); }
public void Execute(IWindsorContainer container) { container.Register( AllTypes.FromAssembly(Assembly.GetExecutingAssembly()) .Where(x => x.Namespace.StartsWith("FakeVader.Core.Services")) .WithService.FirstInterface() ); }
public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register( AllTypes.FromAssembly(Assembly.GetAssembly(typeof(ConfigurationInstaller))) .Pick() .If(f => f.Namespace.Contains("Configuration")) .WithService.DefaultInterface()); }
public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register( AllTypes.FromAssembly(typeof(IFoo).Assembly).Pick(), Classes.FromAssembly(typeof(IFoo).Assembly).Pick(), Castle.MicroKernel.Registration.Types.FromAssembly(typeof(IFoo).Assembly).Pick() ); }
protected override void RegisterImplementationsOfIRegistration() { LookForRegistrations.AssemblyNames .ForEach(n => Container.Register(AllTypes.FromAssemblyNamed(n).BasedOn <IWindsorRegistration>())); LookForRegistrations.Assemblies .ForEach(a => Container.Register(AllTypes.FromAssembly(a).BasedOn <IWindsorRegistration>())); }
public void Execute(IWindsorContainer container) { container.Register( AllTypes.FromAssembly(Assembly.GetExecutingAssembly()) .BasedOn <IController>() .Configure(registration => registration.LifeStyle.Transient) ); }
public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register( AllTypes.FromAssembly(Assembly.GetExecutingAssembly()).Pick(), Classes.FromAssembly(Assembly.GetExecutingAssembly()).Pick(), Castle.MicroKernel.Registration.Types.FromAssembly(Assembly.GetExecutingAssembly()).Pick() ); }
private void RegisterAllTypesBasedOn <T>() { container.Register( AllTypes.FromAssembly(Assembly.GetExecutingAssembly()) .BasedOn <T>() .WithService.FirstInterface() ); }
public void AllTypes_registration_should_register_BasedOn_asignable_types() { container.Register( AllTypes.FromAssembly(Assembly.GetExecutingAssembly()) .BasedOn <IView>().WithService(x => x) ); container.Components.Satisfy(components => components.Any(c => c.Classtype == typeof(FirstView))); }
static void AddMappersTo(IWindsorContainer container) { container.Register( AllTypes .FromAssembly(Assembly.GetAssembly(typeof(BlogController))).Where(m => m.Namespace != null && m.Namespace.Contains(".Mappers")) .WithService.FirstInterface()); container.Register(Component.For(typeof(IMapper <,>)).ImplementedBy(typeof(BaseMapper <,>)).Named("mapper1")); container.Register(Component.For(typeof(IMapper <, ,>)).ImplementedBy(typeof(BaseMapper <, ,>)).Named("mapper2")); }
public void AllTypes_registration_should_register_types_that_satisfy_Where_condition() { container.Register( AllTypes.FromAssembly(Assembly.GetExecutingAssembly()) .Where(t => t.Name.EndsWith("View")).WithService(x => x) ); container.Components.Satisfy(components => components.Any(c => c.Classtype == typeof(FirstView))); }
public void AllTypes_BasedOn_registration_should_use_based_on_type_as_service() { container.Register( AllTypes.FromAssembly(Assembly.GetExecutingAssembly()) .BasedOn <IView>() ); container.Components.Count(c => c.ServiceTypes.Contains(typeof(IView))).Should().Be.EqualTo(2); }
public void AllTypes_registration_should_allow_specification_of_registered_service() { container.Register( AllTypes.FromAssembly(Assembly.GetExecutingAssembly()) .BasedOn <IView>().WithService(x => typeof(int)) ); container.Components.Count(c => c.ServiceTypes.Contains(typeof(int))).Should().Be.EqualTo(2); }
public virtual void Install(IWindsorContainer container, IConfigurationStore store) { //register all IWorkflows container.Register(AllTypes.FromAssembly(GetType().Assembly) .BasedOn(typeof(IWorkflow <,>)) .WithServiceFromInterface(typeof(IWorkflow <,>)) .If(ExtraTypeFilter) .LifestyleTransient()); }
public void RegisterAssembly(Assembly assembly) { _services.Container .Register(AllTypes .FromAssembly(assembly) .Pick() .WithService .FirstInterface()); }
protected virtual void ConfigureContainer() { container.Register( AllTypes.FromAssembly(Assembly) .BasedOn <IDeploymentAction>(), AllTypes.FromAssembly(Assembly) .BasedOn <IEnvironmentValidationAction>() ); RegisterConsumersFrom(Assembly); }
public void RegisterAssemblyTypes_WhenTypeInMissingNamespace_NotRegisteredInContainer() { Kernel.Register( AllTypes.FromAssembly(Assembly.GetExecutingAssembly()) .Where(Component.IsInNamespace("Castle.MicroKernel.Tests.FooBar")) .WithService.FirstInterface() ); Assert.AreEqual(0, Kernel.GetAssignableHandlers(typeof(object)).Length); }
public static void RegisterFromAssembly(Assembly assembly, string classEndsWith, LifeTime lifeTime) { var lifestyle = ConvertLifeStyleType(lifeTime); _container.Register(AllTypes.FromAssembly(assembly) .Where(type => type.Name.EndsWith(classEndsWith)) .WithService.AllInterfaces() .Configure(c => c.LifeStyle.Is(lifestyle)) .WithService.FirstInterface()); }
public void RegisterGenericTypes_BasedOnGenericDefinitionUsingSelect_RegisteredInContainer() { Kernel.Register(AllTypes.FromAssembly(Assembly.GetExecutingAssembly()) .BasedOn <ITask>() .WithService.Select((t, b) => from type in t.GetInterfaces() where !type.Equals(typeof(ITask)) select type)); Assert.IsNotNull(Kernel.Resolve <ITask <object> >()); }