public ServiceDescriptor(Type typeInterface, Type typeClass, ServiceScope scope, ServiceLifeTime lifeTime = ServiceLifeTime.Transient) { if (typeClass == null) { throw new ArgumentNullException(nameof(typeClass)); } Scope = scope; TypeInterface = typeInterface; TypeClass = typeClass; LifeTime = lifeTime; }
public IServiceContainer As <TImplementation>( Func <TImplementation> getService, ServiceLifeTime lifeTime) where TImplementation : T { var keyType = _types.First(); if (_resolver._registrations.ContainsKey(keyType)) { throw new ArgumentException( string.Format("A service is already registered for '{0}'", keyType.FullName), "getService"); } foreach (var type in _types.Skip(1)) { _resolver._registrationKeys.Add(type, keyType); } var fromCache = (Func <IDictionary <Type, object>, Type, Func <TImplementation>, object>) ((c, t, n) => { if (c.ContainsKey(t)) { return(c[t]); } var o = n(); c.Add(t, o); return(o); }); switch (lifeTime) { case ServiceLifeTime.Singleton: _resolver._registrations.Add(keyType, () => fromCache(_resolver._singletonCache, keyType, getService)); break; case ServiceLifeTime.Session: _resolver._registrations.Add(keyType, () => fromCache(_resolver._sessionCache, keyType, getService)); break; case ServiceLifeTime.Transient: _resolver._registrations.Add(keyType, () => getService()); break; } return(_resolver); }
public ServiceDescriptor(Type serviceType, ServiceLifeTime lifetime) { ServiceType = serviceType; Lifetime = lifetime; }
public ServiceDescriptor(Type serviceType, ServiceLifeTime lifetime) { this.ServiceType = serviceType; this.Lifetime = lifetime; }
public ServiceDescriptor(object implementation, ServiceLifeTime lifetime) { ServiceType = implementation.GetType(); Implementation = implementation; Lifetime = lifetime; }
public static void Register <TService, TImplementation>(ServiceLifeTime lifeTime) where TImplementation : TService { serviceDescriptors.Add(new ServiceDescriptor(typeof(TService), typeof(TImplementation), lifeTime)); }
public static void Register <TService>(TService implementation, ServiceLifeTime lifeTime) { serviceDescriptors.Add(new ServiceDescriptor(implementation, lifeTime)); }
public ServieceDescriptor(Type ServiceType, Type ImplementationType, ServiceLifeTime lifeTime) { this.ServiceType = ServiceType; LifeTime = lifeTime; this.ImplementationType = ImplementationType; }
public static void Register <TService>(ServiceLifeTime lifeTime) { serviceDescriptors.Add(new ServiceDescriptor(typeof(TService), lifeTime)); }
/// <summary> /// Create service define. /// </summary> /// <param name="serviceType">Service type.</param> /// <param name="implementInstance">Implemetn instance.</param> /// <param name="implementType">Implement type.</param> /// <param name="implementFactory">Implement factory.</param> /// <param name="lifeTime">Service life time.</param> /// <returns>Service defination.</returns> private static IServiceDefinition CreateServiceDefine(Type serviceType, object implementInstance, Type implementType, Func <object> implementFactory, ServiceLifeTime lifeTime) { if (implementInstance == null && implementType == null && implementFactory == null) { throw new ArgumentNullException("Implement and factory is null."); } if (implementInstance != null) { return(new ServiceDefinition(serviceType, implementInstance)); } else if (implementFactory != null) { return(new ServiceDefinition(serviceType, implementFactory, lifeTime)); } else { return(new ServiceDefinition(serviceType, implementType, lifeTime)); } }
public ServieceDescriptor(object Implementation, ServiceLifeTime lifeTime) { this.Implementation = Implementation; ServiceType = Implementation.GetType(); LifeTime = lifeTime; }
/// <summary> /// Register service with service type and implement factory. /// </summary> /// <typeparam name="TServiceType">Service type.</typeparam> /// <param name="services">Service definition collection.</param> /// <param name="factory">Implement factory.</param> /// <param name="lifeTime">Service life time.</param> public static IServiceDefinitionCollection RegisterService <TServiceType>(this IServiceDefinitionCollection services, Func <object> factory, ServiceLifeTime lifeTime) { return(services.RegisterService(typeof(TServiceType), factory, lifeTime)); }
/// <summary> /// Register service with service type and implement type. /// </summary> /// <typeparam name="TServiceType">Service type.</typeparam> /// <typeparam name="TImplementType">Implement type.</typeparam> /// <param name="services">Service definition collection.</param> /// <param name="lifeTime">Service life time.</param> public static IServiceDefinitionCollection RegisterService <TServiceType, TImplementType>(this IServiceDefinitionCollection services, ServiceLifeTime lifeTime) { return(services.RegisterService(typeof(TServiceType), typeof(TImplementType), lifeTime)); }
public ServiceDefinition(Type serivceType, Type implementType, ServiceLifeTime lifeTime) { this.ServiceType = serivceType; this.ImplementType = implementType; this.LifeTime = lifeTime; }
public ServiceDefinition(Type serivceType, Func <object> factory, ServiceLifeTime lifeTime) { this.ServiceType = serivceType; this.ImplementFactory = factory; this.LifeTime = lifeTime; }
// interface + objet déjà instancié public ServiceDescriptor(Type serviceType, object implementation, ServiceLifeTime lifeTime) { ServiceType = serviceType; Implementation = implementation; LifeTime = lifeTime; }
public ServiceDescriptor(Type serviceType, Type implementationType, ServiceLifeTime lifetime) { ServiceType = serviceType; ImplementationType = implementationType; Lifetime = lifetime; }
/// <summary> /// Register service with service type and implement instance. /// </summary> /// <param name="services">Service definition collection.</param> /// <param name="serviceType">Service type.</param> /// <param name="instance">Implement instance.</param> /// <param name="lifeTime">Service life time.</param> public static IServiceDefinitionCollection RegisterService(this IServiceDefinitionCollection services, Type serviceType, object instance, ServiceLifeTime lifeTime) { if (serviceType == null) { throw new ArgumentNullException("Service type is null."); } services.AddOrUpdateServiceDefinition(serviceType, CreateServiceDefine(serviceType, instance, null, null, lifeTime), (type, old) => CreateServiceDefine(serviceType, instance, null, null, lifeTime)); return(services); }
/// <summary> /// Register service with service type and implement instance. /// </summary> /// <typeparam name="TServiceType">Service type.</typeparam> /// <param name="services">Service definition collection.</param> /// <param name="instance">Implement instance.</param> public static IServiceDefinitionCollection RegisterService <TServiceType>(this IServiceDefinitionCollection services, object instance, ServiceLifeTime lifeTime) { return(services.RegisterService(typeof(TServiceType), instance, lifeTime)); }
public ServieceDescriptor(Type type, ServiceLifeTime lifeTime) { ServiceType = type; LifeTime = lifeTime; }