private static void RegisterEventTypes(IWindsorContainer container, Type type, object instance = null) { Type[] interfaces = type.GetInterfaces(); foreach (Type i in interfaces.Where(x => x.IsGenericType)) { Type genericTypeDefinition = i.GetGenericTypeDefinition(); if (!typeof(IEventHandler <>).IsAssignableFrom(genericTypeDefinition)) { continue; } string genericArguments = string.Join( ", ", i.GetGenericArguments().Select(x => x.ToString())); ComponentRegistration <object> registration = Component.For(i) .Named($"{type.FullName}<{genericArguments}>"); if (instance != null) { registration.Instance(instance); } else { registration.ImplementedBy(type).LifestyleTransient(); } container.Register(registration); } }
private static ComponentRegistration<object> ApplyResolver(ComponentRegistration<object> registration, InstanceResolver resolver) { return registration.Instance(resolver.Instance); }
private static ComponentRegistration <TService> UsingInstance <TService>(ComponentRegistration <TService> registration, Microsoft.Extensions.DependencyInjection.ServiceDescriptor service) where TService : class { return(registration.Instance(service.ImplementationInstance as TService)); }
private static ComponentRegistration <object> ApplyResolver(ComponentRegistration <object> registration, InstanceResolver resolver) { return(registration.Instance(resolver.Instance)); }
private ComponentRegistration<object> InitializeCreationPolicy(IComponent component, ComponentRegistration componentFor) { if (component.Instance != null) { return componentFor.Instance(component.Instance); } if (component.Implementation != null) { return componentFor.ImplementedBy(component.Implementation); } if (component.Factory != null) { return componentFor.UsingFactoryMethod(a => component.Factory(this)); } throw new ContainerException("Implementation not allowed for interface " + component.Interface); }