Files
mws.backend.dotnet/mws.infrastructure/DependencyInjection.cs
T
namdh f72aaa2329 Commit MWS backend source tree
The ASP.NET Core solution (mws.api/mws.application/mws.domain/
mws.infrastructure) existed only as untracked working files. Adding
it to version control, plus a .gitignore for build output and local
tooling directories, so the CQRS/mediator refactor plan has a real
git history to branch and diff against.
2026-08-13 23:10:22 +07:00

53 lines
2.2 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Mws.Application.Accounts;
using Mws.Application.Auth;
using Mws.Application.Common;
using Mws.Application.Documents;
using Mws.Application.Permissions;
using Mws.Application.Projects;
using Mws.Application.Roles;
using Mws.Application.Tasks;
using Mws.Infrastructure.Authentication;
using Mws.Infrastructure.Persistence;
namespace Mws.Infrastructure;
public static class DependencyInjection
{
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
{
var connectionString = configuration.GetConnectionString("Default")
?? "Host=localhost;Port=5432;Database=mws;Username=mws;Password=mws";
services.AddDbContext<AppDbContext>(options => options.UseNpgsql(connectionString));
services.AddScoped<IUnitOfWork, UnitOfWork>();
services.AddAutoMapper(cfg => { }, typeof(MappingProfile).Assembly);
services.AddScoped<IPasswordHasher, BcryptPasswordHasher>();
var jwtSection = configuration.GetSection("Jwt");
var jwtOptions = jwtSection.Get<JwtOptions>() ?? new JwtOptions();
if (string.IsNullOrWhiteSpace(jwtOptions.Secret) || jwtOptions.Secret.Length < 32)
{
jwtOptions.Secret = Environment.GetEnvironmentVariable("MWS_JWT_SECRET")
?? "mws-development-secret-key-change-me-in-production-123456";
}
services.Configure<JwtOptions>(jwtSection.Bind);
services.AddSingleton(jwtOptions);
services.AddScoped<ITokenService, JwtTokenService>();
services.AddScoped<IAuthService, AuthService>();
services.AddScoped<IAccountService, AccountService>();
services.AddScoped<IPermissionService, PermissionService>();
services.AddScoped<IRoleService, RoleService>();
services.AddScoped<IProjectService, ProjectService>();
services.AddScoped<IProjectMemberService, ProjectMemberService>();
services.AddScoped<IDocumentService, DocumentService>();
services.AddScoped<ITaskService, TaskService>();
return services;
}
}