示例#1
0
        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
                });
            }
        }
示例#2
0
 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();
         }
     }
 }
示例#3
0
 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);
         }
     }
 }
示例#4
0
 public DependencyRegistration(string name, Type interfaceOf, ServiceRegistrationType registrationType = ServiceRegistrationType.SCOPED)
     : this(name, registrationType)
 {
     InterfaceOf = interfaceOf;
 }
示例#5
0
 public DependencyRegistration(ServiceRegistrationType registrationType, Type interfaceOf)
     : this(registrationType)
 {
     InterfaceOf = interfaceOf;
 }
示例#6
0
 public DependencyRegistration(string name, ServiceRegistrationType registrationType = ServiceRegistrationType.SCOPED)
     : this(registrationType)
 {
     Name = name;
 }
示例#7
0
 public DependencyRegistration(ServiceRegistrationType registrationType = ServiceRegistrationType.SCOPED)
 {
     RegistrationType = registrationType;
 }