diff --git a/src/WorkFlow.API/Program.cs b/src/WorkFlow.API/Program.cs index 00708f0..a3f7c1b 100644 --- a/src/WorkFlow.API/Program.cs +++ b/src/WorkFlow.API/Program.cs @@ -33,7 +33,7 @@ try // Add services to the container var cnn_str = config.GetConnectionString("Default") ?? throw new("Default connection string not found."); builder.Services.AddDbContext(options => options.UseSqlServer(cnn_str).EnableDetailedErrors()); - builder.Services.AddWorkFlow().AddUserManager(); + builder.Services.AddWorkFlowServices().AddWorkFlowRepositories().AddUserManager(); builder.Services.AddCookieBasedLocalizer(); builder.Services.AddDirectorySearchService(config.GetSection("DirectorySearchOptions")); builder.Services.AddJWTService(user => new SecurityTokenDescriptor() diff --git a/src/WorkFlow.Application/DIExtensions.cs b/src/WorkFlow.Application/DIExtensions.cs deleted file mode 100644 index 4f48499..0000000 --- a/src/WorkFlow.Application/DIExtensions.cs +++ /dev/null @@ -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(); - services.TryAddScoped(); - services.TryAddScoped(); - services.TryAddScoped(); - services.TryAddScoped(); - - return services; - } - - public static IServiceCollection AddWorkFlow(this IServiceCollection services) => services.AddWorkFlowRepositories().AddWorkFlowServices(); - } -} \ No newline at end of file diff --git a/src/WorkFlow.Application/DependencyInjection.cs b/src/WorkFlow.Application/DependencyInjection.cs new file mode 100644 index 0000000..c927c0e --- /dev/null +++ b/src/WorkFlow.Application/DependencyInjection.cs @@ -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(); + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); + + return services; + } +} \ No newline at end of file diff --git a/src/WorkFlow.Infrastructure/DIExtensions.cs b/src/WorkFlow.Infrastructure/DIExtensions.cs deleted file mode 100644 index 71ef479..0000000 --- a/src/WorkFlow.Infrastructure/DIExtensions.cs +++ /dev/null @@ -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(); - services.TryAddScoped(); - services.TryAddScoped(); - services.TryAddScoped(); - services.TryAddScoped(); - - return services; - } - } -} \ No newline at end of file diff --git a/src/WorkFlow.Infrastructure/DependencyInjection.cs b/src/WorkFlow.Infrastructure/DependencyInjection.cs new file mode 100644 index 0000000..34d5350 --- /dev/null +++ b/src/WorkFlow.Infrastructure/DependencyInjection.cs @@ -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(); + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); + + return services; + } +} \ No newline at end of file diff --git a/src/WorkFlow.Infrastructure/Repositories/ConfigRepository.cs b/src/WorkFlow.Infrastructure/Repositories/ConfigRepository.cs index 4c89d61..0b39f29 100644 --- a/src/WorkFlow.Infrastructure/Repositories/ConfigRepository.cs +++ b/src/WorkFlow.Infrastructure/Repositories/ConfigRepository.cs @@ -3,13 +3,12 @@ using DigitalData.Core.Infrastructure; using WorkFlow.Application.Contracts.Repositories; 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, IConfigRepository, ICRUDRepository { - //TODO: Make the db context type generic so that it can be used by other projects with different db contexts. - public class ConfigRepository : CRUDRepository, IConfigRepository, ICRUDRepository + public ConfigRepository(WFDBContext dbContext) : base(dbContext, dbContext.Configs) { - public ConfigRepository(WFDBContext dbContext) : base(dbContext, dbContext.Configs) - { - } } } \ No newline at end of file diff --git a/src/WorkFlow.Infrastructure/Repositories/ProfileControlsTFRepository.cs b/src/WorkFlow.Infrastructure/Repositories/ProfileControlsTFRepository.cs index 56233ed..5121ccf 100644 --- a/src/WorkFlow.Infrastructure/Repositories/ProfileControlsTFRepository.cs +++ b/src/WorkFlow.Infrastructure/Repositories/ProfileControlsTFRepository.cs @@ -4,51 +4,50 @@ using Microsoft.EntityFrameworkCore; using WorkFlow.Application.Contracts.Repositories; using WorkFlow.Domain.Entities; -namespace WorkFlow.Infrastructure.Repositories +namespace WorkFlow.Infrastructure.Repositories; + +public class ProfileControlsTFRepository : CRUDRepository, IProfileControlsTFRepository, ICRUDRepository { - public class ProfileControlsTFRepository : CRUDRepository, IProfileControlsTFRepository, ICRUDRepository + public ProfileControlsTFRepository(WFDBContext dbContext) : base(dbContext, dbContext.ProfileControlsTFs) { - public ProfileControlsTFRepository(WFDBContext dbContext) : base(dbContext, dbContext.ProfileControlsTFs) - { - } - - protected override IQueryable ReadOnly() => base.ReadOnly().Include(pctf => pctf.Profile).Include(pctf => pctf.User); - - protected IQueryable 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> 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 ReadOnly() => base.ReadOnly().Include(pctf => pctf.Profile).Include(pctf => pctf.User); + + protected IQueryable 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> 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(); } \ No newline at end of file