/// <summary>
 /// Add Scoped
 /// </summary>
 /// <param name="bag"></param>
 /// <param name="implementationFunc"></param>
 /// <typeparam name="TService"></typeparam>
 /// <typeparam name="TImplementation"></typeparam>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static R AddScoped <TService, TImplementation>(this R bag, Func <IDefinedResolver, TImplementation> implementationFunc)
 {
     bag.CheckNull(nameof(bag));
     implementationFunc.CheckNull(nameof(implementationFunc));
     bag.Register(DependencyProxyDescriptor.CreateForResolvedServiceDelegate <TService, TImplementation>(implementationFunc, DependencyLifetimeType.Scoped));
     return(bag);
 }
 /// <summary>
 /// Add Singleton
 /// </summary>
 /// <param name="bag"></param>
 /// <param name="implementationFunc"></param>
 /// <typeparam name="TService"></typeparam>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static R AddSingletonService <TService>(this R bag, Func <IDefinedResolver, TService> implementationFunc)
 {
     bag.CheckNull(nameof(bag));
     implementationFunc.CheckNull(nameof(implementationFunc));
     bag.Register(DependencyProxyDescriptor.CreateForResolvedServiceDelegate <TService>(resolver => implementationFunc(resolver), DependencyLifetimeType.Singleton));
     return(bag);
 }
 /// <summary>
 /// Try add Scoped
 /// </summary>
 /// <param name="bag"></param>
 /// <param name="implementationFunc"></param>
 /// <typeparam name="TService"></typeparam>
 /// <exception cref="ArgumentNullException"></exception>
 public static void TryAddScopedService <TService>(this R bag, Func <IDefinedResolver, object> implementationFunc)
 {
     bag.CheckNull(nameof(bag));
     implementationFunc.CheckNull(nameof(implementationFunc));
     bag.TryRegister(DependencyProxyDescriptor.CreateForResolvedServiceDelegate <TService>(implementationFunc, DependencyLifetimeType.Scoped));
 }
Example #4
0
 /// <summary>
 /// Try add Transient
 /// </summary>
 /// <param name="bag"></param>
 /// <param name="implementationFunc"></param>
 /// <typeparam name="TService"></typeparam>
 /// <exception cref="ArgumentNullException"></exception>
 public static void TryAddTransientService <TService>(this R bag, Func <IDefinedResolver, TService> implementationFunc)
 {
     bag.CheckNull(nameof(bag));
     implementationFunc.CheckNull(nameof(implementationFunc));
     bag.TryRegister(DependencyProxyDescriptor.CreateForResolvedServiceDelegate <TService>(resolver => implementationFunc(resolver), DependencyLifetimeType.Transient));
 }