public static ContainerBuilder RegisterNimbus(this ContainerBuilder builder, ITypeProvider typeProvider) { foreach (var handlerType in typeProvider.AllHandlerTypes()) { var handlerInterfaceTypes = handlerType.GetInterfaces().Where(typeProvider.IsClosedGenericHandlerInterface); foreach (var interfaceType in handlerInterfaceTypes) { builder.RegisterType(handlerType) .Named(handlerType.FullName, interfaceType) .InstancePerLifetimeScope(); } } builder.RegisterSource(new ContravariantRegistrationSource()); typeProvider.InterceptorTypes .Do(t => builder.RegisterType(t) .AsSelf() .InstancePerLifetimeScope()) .Done(); builder.RegisterInstance(typeProvider) .AsImplementedInterfaces() .SingleInstance(); builder.RegisterType<AutofacDependencyResolver>() .As<IDependencyResolver>() .SingleInstance(); return builder; }
public static ContainerBuilder RegisterNimbus(this ContainerBuilder builder, ITypeProvider typeProvider) { builder.RegisterTypes(typeProvider.AllHandlerTypes()) .AsImplementedInterfaces() .InstancePerLifetimeScope(); builder.RegisterType<AutofacMulticastEventHandlerFactory>() .AsImplementedInterfaces() .SingleInstance(); builder.RegisterType<AutofacCompetingEventHandlerFactory>() .AsImplementedInterfaces() .SingleInstance(); builder.RegisterType<AutofacCommandHandlerFactory>() .AsImplementedInterfaces() .SingleInstance(); builder.RegisterType<AutofacRequestHandlerFactory>() .AsImplementedInterfaces() .SingleInstance(); builder.RegisterType<AutofacMulticastRequestHandlerFactory>() .AsImplementedInterfaces() .SingleInstance(); return builder; }
public static Type[] AllClosedGenericHandlerInterfaces(this ITypeProvider typeProvider) { return(typeProvider.AllHandlerTypes() .SelectMany(t => t.GetInterfaces()) .Where(typeProvider.IsClosedGenericHandlerInterface) .ToArray()); }
public static Type[] AllResolvableTypes(this ITypeProvider typeProvider) { return(Enumerable.Empty <Type>() .Union(typeProvider.AllHandlerTypes()) .Union(typeProvider.FilterTypes) .Union(typeProvider.InterceptorTypes) .ToArray()); }
private static void BindAllHandlerInterfaces(IBindingRoot kernel, ITypeProvider typeProvider) { typeProvider.AllHandlerTypes() .ToList() .ForEach( handlerType => handlerType.GetInterfaces() .Where(typeProvider.IsClosedGenericHandlerInterface) .ToList() .ForEach(interfaceType => kernel.Bind(interfaceType).To(handlerType).InTransientScope())); }
public static IWindsorContainer RegisterNimbus(this IWindsorContainer container, ITypeProvider typeProvider) { container.Register( Classes.From(typeProvider.AllHandlerTypes()).Pick().WithServiceAllInterfaces().LifestyleScoped(), Component.For<IMulticastEventBroker>().ImplementedBy<WindsorMulticastEventBroker>().LifestyleSingleton(), Component.For<ICompetingEventBroker>().ImplementedBy<WindsorCompetingEventBroker>().LifestyleSingleton(), Component.For<ICommandBroker>().ImplementedBy<WindsorCommandBroker>().LifestyleSingleton(), Component.For<IRequestBroker>().ImplementedBy<WindsorRequestBroker>().LifestyleSingleton(), Component.For<IMulticastRequestBroker>().ImplementedBy<WindsorMulticastRequestBroker>().LifestyleSingleton() ); return container; }
public static IWindsorContainer RegisterNimbus(this IWindsorContainer container, ITypeProvider typeProvider) { container.Register( Component.For<IDependencyResolver>().ImplementedBy<WindsorDependencyResolver>().LifestyleSingleton(), Component.For<ITypeProvider>().Instance(typeProvider).LifestyleSingleton() ); container.Register( Classes.From(typeProvider.AllHandlerTypes()) .Where(t => true) .WithServiceSelect((t, bt) => SelectHandlerInterfaces(t, typeProvider)) .Configure(ConfigureComponent) .LifestyleScoped() ); return container; }
public static IWindsorContainer RegisterNimbus(this IWindsorContainer container, ITypeProvider typeProvider) { container.Register( Component.For<IDependencyResolver>().ImplementedBy<WindsorDependencyResolver>().LifestyleSingleton(), Component.For<ITypeProvider>().Instance(typeProvider).LifestyleSingleton() ); foreach (var handlerType in typeProvider.AllHandlerTypes()) { var handlerInterfaceTypes = handlerType.GetInterfaces().Where(typeProvider.IsClosedGenericHandlerInterface); foreach (var interfaceType in handlerInterfaceTypes) { container.Register(Component.For(interfaceType).ImplementedBy(handlerType).Named(handlerType.FullName).LifestyleScoped()); } } return container; }