using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Text; using Microsoft.Extensions.Logging; using Microsoft.Extensions.DependencyInjection; namespace DG.EntityFramework { /// /// Extensions method /// public static class ServiceCollectionExtensions { /// /// Add EntityFramework /// /// /// /// /// /// public static IServiceCollection AddDGEntityFramework(this IServiceCollection services, Action options) where TDbContext : DbContext { if (options == null) { throw new ArgumentNullException(nameof(options)); } services.AddDbContext(options, ServiceLifetime.Scoped, ServiceLifetime.Scoped); services.AddScoped>(); services.AddScoped, DbContextProvider>(); services.AddScoped(typeof(IRepositoryBase<,>), typeof(RepositoryBase<,>)); services.AddScoped(typeof(IBaseRepository<>), typeof(BaseRepository<>)); return services; } } }