private static void AddToStack(Type type) { ServiceRegistrationType registrationType = GetRegistrationType(type); Type interfaceOf = GetRegistrationInterfaceType(type); Type[] interfaces = type.GetInterfaces(); if (interfaceOf == null && interfaces.Length > 0) { for (int i = 0; i < interfaces.Length; i++) { _serviceRegistrations.Add(new ServiceRegistration { ServiceType = interfaces[i], ImplementationType = type, Type = registrationType }); } } else { _serviceRegistrations.Add(new ServiceRegistration { ServiceType = interfaceOf, ImplementationType = type, Type = registrationType }); } }
private static void Register(ContainerBuilder builder, ServiceRegistrationType registrationType, Type serviceType, Type implementationType) { if (registrationType == ServiceRegistrationType.SCOPED) { if (serviceType != null) { builder.RegisterType(implementationType) .As(serviceType) .InstancePerLifetimeScope(); } else { builder.RegisterType(implementationType) .InstancePerLifetimeScope(); } } else if (registrationType == ServiceRegistrationType.TRANSIENT) { if (serviceType != null) { builder.RegisterType(implementationType) .As(serviceType); } else { builder.RegisterType(implementationType); } } else { if (serviceType != null) { builder.RegisterType(implementationType) .As(serviceType) .SingleInstance(); } else { builder.RegisterType(implementationType) .SingleInstance(); } } }
private static void Register(IServiceCollection services, ServiceRegistrationType registrationType, Type serviceType, Type implementationType) { if (registrationType == ServiceRegistrationType.SCOPED) { if (serviceType != null) { services.AddScoped(serviceType, implementationType); } else { services.AddScoped(implementationType); } } else if (registrationType == ServiceRegistrationType.TRANSIENT) { if (serviceType != null) { services.AddTransient(serviceType, implementationType); } else { services.AddTransient(implementationType); } } else { if (serviceType != null) { services.AddSingleton(serviceType, implementationType); } else { services.AddSingleton(implementationType); } } }
public DependencyRegistration(string name, Type interfaceOf, ServiceRegistrationType registrationType = ServiceRegistrationType.SCOPED) : this(name, registrationType) { InterfaceOf = interfaceOf; }
public DependencyRegistration(ServiceRegistrationType registrationType, Type interfaceOf) : this(registrationType) { InterfaceOf = interfaceOf; }
public DependencyRegistration(string name, ServiceRegistrationType registrationType = ServiceRegistrationType.SCOPED) : this(registrationType) { Name = name; }
public DependencyRegistration(ServiceRegistrationType registrationType = ServiceRegistrationType.SCOPED) { RegistrationType = registrationType; }