EF: refactoring
This commit is contained in:
parent
aed98bea9a
commit
5d7f58cc2c
@ -1,8 +1,7 @@
|
||||
using ASC.Core.Common.EF.Model;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Common.EF.Context
|
||||
{
|
||||
@ -20,11 +19,7 @@ namespace ASC.Core.Common.EF.Context
|
||||
{
|
||||
public static IServiceCollection AddAccountLinkContextService(this IServiceCollection services)
|
||||
{
|
||||
services.TryAddScoped<DbContextManager<AccountLinkContext>>();
|
||||
services.TryAddScoped<IConfigureOptions<AccountLinkContext>, ConfigureDbContext>();
|
||||
services.TryAddScoped<AccountLinkContext>();
|
||||
|
||||
return services;
|
||||
return services.AddDbContextManagerService<AccountLinkContext>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Common.EF
|
||||
{
|
||||
@ -29,11 +27,7 @@ namespace ASC.Core.Common.EF
|
||||
{
|
||||
public static IServiceCollection AddCoreDbContextService(this IServiceCollection services)
|
||||
{
|
||||
services.TryAddScoped<DbContextManager<CoreDbContext>>();
|
||||
services.TryAddScoped<IConfigureOptions<CoreDbContext>, ConfigureDbContext>();
|
||||
services.TryAddScoped<CoreDbContext>();
|
||||
|
||||
return services;
|
||||
return services.AddDbContextManagerService<CoreDbContext>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Common.EF
|
||||
@ -53,4 +55,16 @@ namespace ASC.Core.Common.EF
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class DbContextManagerExtension
|
||||
{
|
||||
public static IServiceCollection AddDbContextManagerService<T>(this IServiceCollection services) where T : BaseDbContext, new()
|
||||
{
|
||||
services.TryAddScoped<DbContextManager<T>>();
|
||||
services.TryAddScoped<IConfigureOptions<T>, ConfigureDbContext>();
|
||||
services.TryAddScoped<T>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Common.EF.Context
|
||||
{
|
||||
@ -26,11 +24,7 @@ namespace ASC.Core.Common.EF.Context
|
||||
{
|
||||
public static IServiceCollection AddFeedDbService(this IServiceCollection services)
|
||||
{
|
||||
services.TryAddScoped<DbContextManager<FeedDbContext>>();
|
||||
services.TryAddScoped<IConfigureOptions<FeedDbContext>, ConfigureDbContext>();
|
||||
services.TryAddScoped<FeedDbContext>();
|
||||
|
||||
return services;
|
||||
return services.AddDbContextManagerService<FeedDbContext>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Common.EF.Context
|
||||
{
|
||||
@ -21,11 +19,7 @@ namespace ASC.Core.Common.EF.Context
|
||||
{
|
||||
public static IServiceCollection AddFilesDbContextService(this IServiceCollection services)
|
||||
{
|
||||
services.TryAddScoped<DbContextManager<FilesDbContext>>();
|
||||
services.TryAddScoped<IConfigureOptions<FilesDbContext>, ConfigureDbContext>();
|
||||
services.TryAddScoped<FilesDbContext>();
|
||||
|
||||
return services;
|
||||
return services.AddDbContextManagerService<FilesDbContext>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
using ASC.Core.Common.EF.Model;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Common.EF.Context
|
||||
{
|
||||
@ -23,11 +22,7 @@ namespace ASC.Core.Common.EF.Context
|
||||
{
|
||||
public static IServiceCollection AddMessagesContextService(this IServiceCollection services)
|
||||
{
|
||||
services.TryAddScoped<DbContextManager<MessagesContext>>();
|
||||
services.TryAddScoped<IConfigureOptions<MessagesContext>, ConfigureDbContext>();
|
||||
services.TryAddScoped<MessagesContext>();
|
||||
|
||||
return services;
|
||||
return services.AddDbContextManagerService<MessagesContext>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Common.EF.Context
|
||||
{
|
||||
@ -17,11 +15,7 @@ namespace ASC.Core.Common.EF.Context
|
||||
{
|
||||
public static IServiceCollection AddNotifyDbContext(this IServiceCollection services)
|
||||
{
|
||||
services.TryAddScoped<DbContextManager<NotifyDbContext>>();
|
||||
services.TryAddScoped<IConfigureOptions<NotifyDbContext>, ConfigureDbContext>();
|
||||
services.TryAddScoped<NotifyDbContext>();
|
||||
|
||||
return services;
|
||||
return services.AddDbContextManagerService<NotifyDbContext>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Common.EF.Context
|
||||
{
|
||||
@ -36,11 +34,7 @@ namespace ASC.Core.Common.EF.Context
|
||||
{
|
||||
public static IServiceCollection AddTenantDbContextService(this IServiceCollection services)
|
||||
{
|
||||
services.TryAddScoped<DbContextManager<TenantDbContext>>();
|
||||
services.TryAddScoped<IConfigureOptions<TenantDbContext>, ConfigureDbContext>();
|
||||
services.TryAddScoped<TenantDbContext>();
|
||||
|
||||
return services;
|
||||
return services.AddDbContextManagerService<TenantDbContext>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Common.EF
|
||||
{
|
||||
@ -34,11 +32,7 @@ namespace ASC.Core.Common.EF
|
||||
{
|
||||
public static IServiceCollection AddUserDbContextService(this IServiceCollection services)
|
||||
{
|
||||
services.TryAddScoped<DbContextManager<UserDbContext>>();
|
||||
services.TryAddScoped<IConfigureOptions<UserDbContext>, ConfigureDbContext>();
|
||||
services.TryAddScoped<UserDbContext>();
|
||||
|
||||
return services;
|
||||
return services.AddDbContextManagerService<UserDbContext>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Core.Common.EF.Context
|
||||
{
|
||||
@ -24,11 +22,7 @@ namespace ASC.Core.Common.EF.Context
|
||||
{
|
||||
public static IServiceCollection AddWebstudioDbContextService(this IServiceCollection services)
|
||||
{
|
||||
services.TryAddScoped<DbContextManager<WebstudioDbContext>>();
|
||||
services.TryAddScoped<IConfigureOptions<WebstudioDbContext>, ConfigureDbContext>();
|
||||
services.TryAddScoped<WebstudioDbContext>();
|
||||
|
||||
return services;
|
||||
return services.AddDbContextManagerService<WebstudioDbContext>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user