chore: update dependency injection methods of repositories
This commit is contained in:
parent
a9faf74803
commit
30bb3ffa11
@ -33,7 +33,7 @@ try
|
|||||||
// Add services to the container
|
// Add services to the container
|
||||||
var cnn_str = config.GetConnectionString("Default") ?? throw new("Default connection string not found.");
|
var cnn_str = config.GetConnectionString("Default") ?? throw new("Default connection string not found.");
|
||||||
builder.Services.AddDbContext<WFDBContext>(options => options.UseSqlServer(cnn_str).EnableDetailedErrors());
|
builder.Services.AddDbContext<WFDBContext>(options => options.UseSqlServer(cnn_str).EnableDetailedErrors());
|
||||||
builder.Services.AddWorkFlow().AddUserManager<WFDBContext>();
|
builder.Services.AddWorkFlowServices().AddWorkFlowRepositories().AddUserManager<WFDBContext>();
|
||||||
builder.Services.AddCookieBasedLocalizer();
|
builder.Services.AddCookieBasedLocalizer();
|
||||||
builder.Services.AddDirectorySearchService(config.GetSection("DirectorySearchOptions"));
|
builder.Services.AddDirectorySearchService(config.GetSection("DirectorySearchOptions"));
|
||||||
builder.Services.AddJWTService<UserReadDto>(user => new SecurityTokenDescriptor()
|
builder.Services.AddJWTService<UserReadDto>(user => new SecurityTokenDescriptor()
|
||||||
|
|||||||
@ -1,25 +0,0 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
||||||
using WorkFlow.Application.Contracts;
|
|
||||||
using WorkFlow.Application.Services;
|
|
||||||
using WorkFlow.Infrastructure;
|
|
||||||
|
|
||||||
namespace WorkFlow.Application
|
|
||||||
{
|
|
||||||
public static class DIExtensions
|
|
||||||
{
|
|
||||||
public static IServiceCollection AddWorkFlowServices(this IServiceCollection services)
|
|
||||||
{
|
|
||||||
services.AddAutoMapper(typeof(MappingProfile).Assembly);
|
|
||||||
services.TryAddScoped<IConfigService, ConfigService>();
|
|
||||||
services.TryAddScoped<IProfileControlsTFService, ProfileControlsTFService>();
|
|
||||||
services.TryAddScoped<IProfileObjStateService, ProfileObjStateService>();
|
|
||||||
services.TryAddScoped<IProfileService, ProfileService>();
|
|
||||||
services.TryAddScoped<IStateService, StateService>();
|
|
||||||
|
|
||||||
return services;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IServiceCollection AddWorkFlow(this IServiceCollection services) => services.AddWorkFlowRepositories().AddWorkFlowServices();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
21
src/WorkFlow.Application/DependencyInjection.cs
Normal file
21
src/WorkFlow.Application/DependencyInjection.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
|
using WorkFlow.Application.Contracts;
|
||||||
|
using WorkFlow.Application.Services;
|
||||||
|
|
||||||
|
namespace WorkFlow.Application;
|
||||||
|
|
||||||
|
public static class DependencyInjection
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddWorkFlowServices(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddAutoMapper(typeof(MappingProfile).Assembly);
|
||||||
|
services.TryAddScoped<IConfigService, ConfigService>();
|
||||||
|
services.TryAddScoped<IProfileControlsTFService, ProfileControlsTFService>();
|
||||||
|
services.TryAddScoped<IProfileObjStateService, ProfileObjStateService>();
|
||||||
|
services.TryAddScoped<IProfileService, ProfileService>();
|
||||||
|
services.TryAddScoped<IStateService, StateService>();
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,20 +0,0 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
||||||
using WorkFlow.Infrastructure.Repositories;
|
|
||||||
|
|
||||||
namespace WorkFlow.Infrastructure
|
|
||||||
{
|
|
||||||
public static class DIExtensions
|
|
||||||
{
|
|
||||||
public static IServiceCollection AddWorkFlowRepositories(this IServiceCollection services)
|
|
||||||
{
|
|
||||||
services.TryAddScoped<IConfigRepository, ConfigRepository>();
|
|
||||||
services.TryAddScoped<IProfileControlsTFRepository, ProfileControlsTFRepository>();
|
|
||||||
services.TryAddScoped<IProfileObjStateRepository, ProfileObjStateRepository>();
|
|
||||||
services.TryAddScoped<IProfileRepository, ProfileRepository>();
|
|
||||||
services.TryAddScoped<IStateRepository, StateRepository>();
|
|
||||||
|
|
||||||
return services;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
20
src/WorkFlow.Infrastructure/DependencyInjection.cs
Normal file
20
src/WorkFlow.Infrastructure/DependencyInjection.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
|
using WorkFlow.Application.Contracts.Repositories;
|
||||||
|
using WorkFlow.Infrastructure.Repositories;
|
||||||
|
|
||||||
|
namespace WorkFlow.Infrastructure;
|
||||||
|
|
||||||
|
public static class DependencyInjection
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddWorkFlowRepositories(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.TryAddScoped<IConfigRepository, ConfigRepository>();
|
||||||
|
services.TryAddScoped<IProfileControlsTFRepository, ProfileControlsTFRepository>();
|
||||||
|
services.TryAddScoped<IProfileObjStateRepository, ProfileObjStateRepository>();
|
||||||
|
services.TryAddScoped<IProfileRepository, ProfileRepository>();
|
||||||
|
services.TryAddScoped<IStateRepository, StateRepository>();
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,13 +3,12 @@ using DigitalData.Core.Infrastructure;
|
|||||||
using WorkFlow.Application.Contracts.Repositories;
|
using WorkFlow.Application.Contracts.Repositories;
|
||||||
using WorkFlow.Domain.Entities;
|
using WorkFlow.Domain.Entities;
|
||||||
|
|
||||||
namespace WorkFlow.Infrastructure.Repositories
|
namespace WorkFlow.Infrastructure.Repositories;
|
||||||
|
|
||||||
|
//TODO: Make the db context type generic so that it can be used by other projects with different db contexts.
|
||||||
|
public class ConfigRepository : CRUDRepository<Config, int, WFDBContext>, IConfigRepository, ICRUDRepository<Config, int>
|
||||||
{
|
{
|
||||||
//TODO: Make the db context type generic so that it can be used by other projects with different db contexts.
|
public ConfigRepository(WFDBContext dbContext) : base(dbContext, dbContext.Configs)
|
||||||
public class ConfigRepository : CRUDRepository<Config, int, WFDBContext>, IConfigRepository, ICRUDRepository<Config, int>
|
|
||||||
{
|
{
|
||||||
public ConfigRepository(WFDBContext dbContext) : base(dbContext, dbContext.Configs)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4,51 +4,50 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using WorkFlow.Application.Contracts.Repositories;
|
using WorkFlow.Application.Contracts.Repositories;
|
||||||
using WorkFlow.Domain.Entities;
|
using WorkFlow.Domain.Entities;
|
||||||
|
|
||||||
namespace WorkFlow.Infrastructure.Repositories
|
namespace WorkFlow.Infrastructure.Repositories;
|
||||||
|
|
||||||
|
public class ProfileControlsTFRepository : CRUDRepository<ProfileControlsTF, int, WFDBContext>, IProfileControlsTFRepository, ICRUDRepository<ProfileControlsTF, int>
|
||||||
{
|
{
|
||||||
public class ProfileControlsTFRepository : CRUDRepository<ProfileControlsTF, int, WFDBContext>, IProfileControlsTFRepository, ICRUDRepository<ProfileControlsTF, int>
|
public ProfileControlsTFRepository(WFDBContext dbContext) : base(dbContext, dbContext.ProfileControlsTFs)
|
||||||
{
|
{
|
||||||
public ProfileControlsTFRepository(WFDBContext dbContext) : base(dbContext, dbContext.ProfileControlsTFs)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override IQueryable<ProfileControlsTF> ReadOnly() => base.ReadOnly().Include(pctf => pctf.Profile).Include(pctf => pctf.User);
|
|
||||||
|
|
||||||
protected IQueryable<ProfileControlsTF> Read(bool isReadonly = false, bool withProfile = true, bool withUser = true, int? profileId = null, int? userId = null, string? username = null, int? objId = null)
|
|
||||||
{
|
|
||||||
var query = isReadonly ? _dbSet.AsNoTracking() : _dbSet.AsQueryable();
|
|
||||||
|
|
||||||
if (withProfile)
|
|
||||||
query = query.Include(pctf => pctf.Profile);
|
|
||||||
|
|
||||||
if (withUser)
|
|
||||||
query = query.Include(pctf => pctf.User);
|
|
||||||
|
|
||||||
if (profileId is not null)
|
|
||||||
query = query.Where(pctf => pctf.ProfileId == profileId);
|
|
||||||
|
|
||||||
if (userId is not null)
|
|
||||||
query = query.Where(pctf => pctf.UserId == userId);
|
|
||||||
|
|
||||||
if (username is null)
|
|
||||||
query = query.Where(pctf => pctf.User!.Username == username);
|
|
||||||
|
|
||||||
if (objId is not null)
|
|
||||||
query = query.Where(pctf => pctf.ObjId == objId);
|
|
||||||
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IEnumerable<ProfileControlsTF>> ReadAsync(
|
|
||||||
bool isReadonly = true,
|
|
||||||
bool withProfile = true, bool withUser = true,
|
|
||||||
int? userId = null, string? username = null,
|
|
||||||
int? profileId = null, int? objId = null, bool? profileActive = null)
|
|
||||||
=> await Read(
|
|
||||||
isReadonly: isReadonly,
|
|
||||||
withProfile: withProfile, withUser: withUser,
|
|
||||||
userId: userId, username: username,
|
|
||||||
profileId: profileId, objId: objId)
|
|
||||||
.ToListAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override IQueryable<ProfileControlsTF> ReadOnly() => base.ReadOnly().Include(pctf => pctf.Profile).Include(pctf => pctf.User);
|
||||||
|
|
||||||
|
protected IQueryable<ProfileControlsTF> Read(bool isReadonly = false, bool withProfile = true, bool withUser = true, int? profileId = null, int? userId = null, string? username = null, int? objId = null)
|
||||||
|
{
|
||||||
|
var query = isReadonly ? _dbSet.AsNoTracking() : _dbSet.AsQueryable();
|
||||||
|
|
||||||
|
if (withProfile)
|
||||||
|
query = query.Include(pctf => pctf.Profile);
|
||||||
|
|
||||||
|
if (withUser)
|
||||||
|
query = query.Include(pctf => pctf.User);
|
||||||
|
|
||||||
|
if (profileId is not null)
|
||||||
|
query = query.Where(pctf => pctf.ProfileId == profileId);
|
||||||
|
|
||||||
|
if (userId is not null)
|
||||||
|
query = query.Where(pctf => pctf.UserId == userId);
|
||||||
|
|
||||||
|
if (username is null)
|
||||||
|
query = query.Where(pctf => pctf.User!.Username == username);
|
||||||
|
|
||||||
|
if (objId is not null)
|
||||||
|
query = query.Where(pctf => pctf.ObjId == objId);
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<ProfileControlsTF>> ReadAsync(
|
||||||
|
bool isReadonly = true,
|
||||||
|
bool withProfile = true, bool withUser = true,
|
||||||
|
int? userId = null, string? username = null,
|
||||||
|
int? profileId = null, int? objId = null, bool? profileActive = null)
|
||||||
|
=> await Read(
|
||||||
|
isReadonly: isReadonly,
|
||||||
|
withProfile: withProfile, withUser: withUser,
|
||||||
|
userId: userId, username: username,
|
||||||
|
profileId: profileId, objId: objId)
|
||||||
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user