public ServiceBuilder RegisterInstance(object instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            var item = new ServiceBuilder
            {
                ImplementationInstance = instance
            };

            _builders.Add(item);
            return(item);
        }
        public ServiceBuilder Register(Func <IServiceProvider, object> factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            var item = new ServiceBuilder
            {
                ImplementationFactory = factory
            };

            _builders.Add(item);
            return(item);
        }
        public ServiceBuilder RegisterType(Type implementationType)
        {
            if (implementationType == null)
            {
                throw new ArgumentNullException(nameof(implementationType));
            }

            var item = new ServiceBuilder
            {
                ImplementationType = implementationType
            };

            _builders.Add(item);
            return(item);
        }
示例#4
0
 public static ServiceBuilder As <TService>(this ServiceBuilder builder)
 {
     return(builder.As(typeof(TService)));
 }
示例#5
0
 public static ServiceBuilder Keyed <TService>(this ServiceBuilder builder, object keyed)
 {
     return(builder.Keyed(typeof(TService), keyed));
 }
示例#6
0
 public static ServiceBuilder Keyed(this ServiceBuilder builder, Type serviceType, object keyed)
 {
     builder.ServiceKeys.Add(new KeyedServiceKey(serviceType, keyed));
     return(builder);
 }
示例#7
0
 public static ServiceBuilder Named <TService>(this ServiceBuilder builder, string named)
 {
     return(builder.Named(typeof(TService), named));
 }
示例#8
0
 public static ServiceBuilder Named(this ServiceBuilder builder, Type serviceType, string named)
 {
     return(builder.Keyed(serviceType, named));
 }
示例#9
0
 public static ServiceBuilder Lifetime(this ServiceBuilder builder, ServiceLifetime lifetime)
 {
     builder.Lifetime = lifetime;
     return(builder);
 }
示例#10
0
 public static ServiceBuilder Transient(this ServiceBuilder builder)
 {
     return(builder.Lifetime(ServiceLifetime.Transient));
 }
示例#11
0
 public static ServiceBuilder Scoped(this ServiceBuilder builder)
 {
     return(builder.Lifetime(ServiceLifetime.Scoped));
 }
示例#12
0
 public static ServiceBuilder Singleton(this ServiceBuilder builder)
 {
     return(builder.Lifetime(ServiceLifetime.Singleton));
 }
示例#13
0
 public static ServiceBuilder As(this ServiceBuilder builder, Type serviceType)
 {
     builder.ServiceKeys.Add(new ServiceKey(serviceType));
     return(builder);
 }