Ejemplo n.º 1
0
 /// <summary>
 /// Adds an internal service with a scoped life time.
 /// </summary>
 /// <typeparam name="TService">Clr type of the contract.</typeparam>
 /// <typeparam name="TImplementation">Clr type of the implementation.</typeparam>
 /// <param name="options">Detached Options instance.</param>
 /// <returns>The same DetachedOptionsExtensions, for chaining calls.</returns>
 public static DetachedOptionsExtension AddScoped <TService, TImplementation>(this DetachedOptionsExtension options)
     where TService : class
     where TImplementation : class, TService
 {
     options.DetachedServices.AddScoped <TService, TImplementation>();
     return(options);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Configures the DbContext to use EntityFramework.Detached.
        /// </summary>
        /// <param name="builder">The DbContextOptionsBuilder instance.</param>
        /// <param name="options">A delegate that configures the Detached Options.</param>
        /// <returns>The same DbCotnextOptionsBuilder for chaining calls.</returns>
        public static DbContextOptionsBuilder UseDetached(this DbContextOptionsBuilder builder, Action <DetachedOptionsExtension> options = null)
        {
            DetachedOptionsExtension detachedOptions = new DetachedOptionsExtension();

            options?.Invoke(detachedOptions);
            ((IDbContextOptionsBuilderInfrastructure)builder).AddOrUpdateExtension(detachedOptions);
            return(builder);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Adds an internal service with a singleton life time.
 /// </summary>
 /// <typeparam name="TService">Clr Type of the Contract.</typeparam>
 /// <param name="options">Detached Options instance.</param>
 /// <param name="instance">Service implementation instance.</param>
 /// <returns>The same DetachedOptionsExtensions, for chaining calls.</returns>
 public static DetachedOptionsExtension AddSingleton <TService>(this DetachedOptionsExtension options, TService instance)
     where TService : class
 {
     options.DetachedServices.AddSingleton(instance);
     return(options);
 }