181 lines
7.2 KiB
C#
181 lines
7.2 KiB
C#
using CPRNIMS.Domain.Contracts.Account;
|
|
using CPRNIMS.Domain.Contracts.Canvass;
|
|
using CPRNIMS.Domain.Contracts.Common;
|
|
using CPRNIMS.Domain.Contracts.Finance;
|
|
using CPRNIMS.Domain.Contracts.Inventory;
|
|
using CPRNIMS.Domain.Contracts.Items;
|
|
using CPRNIMS.Domain.Contracts.PO;
|
|
using CPRNIMS.Domain.Contracts.PR;
|
|
using CPRNIMS.Domain.Contracts.Receiving;
|
|
using CPRNIMS.Domain.Contracts.Reports;
|
|
using CPRNIMS.Domain.Contracts.SMTP;
|
|
using CPRNIMS.Domain.Services;
|
|
using CPRNIMS.Domain.Services.Account;
|
|
using CPRNIMS.Domain.Services.Canvass;
|
|
using CPRNIMS.Domain.Services.Common;
|
|
using CPRNIMS.Domain.Services.Finance;
|
|
using CPRNIMS.Domain.Services.Inventory;
|
|
using CPRNIMS.Domain.Services.PO;
|
|
using CPRNIMS.Domain.Services.Receiving;
|
|
using CPRNIMS.Domain.Services.SMTP;
|
|
using CPRNIMS.Infrastructure.Database;
|
|
using CPRNIMS.Infrastructure.Entities.Account;
|
|
using CPRNIMS.Infrastructure.Helper;
|
|
using CPRNIMS.Infrastructure.Reports;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.IdentityModel.Tokens;
|
|
using Microsoft.OpenApi.Models;
|
|
using System.Text;
|
|
|
|
|
|
namespace CPRNIMS.WebApi.Common
|
|
{
|
|
public static class ServiceExtensions
|
|
{
|
|
public static void AddApplicationServices(this IServiceCollection services, WebApplicationBuilder builder)
|
|
{
|
|
AddIdentityServices(services);
|
|
AddDbContexts(builder, services);
|
|
AddMvcServices(services);
|
|
AddAuthenticationServices(builder, services);
|
|
AddCorsServices(services);
|
|
AddOtherServices(services);
|
|
|
|
|
|
services.AddControllers();
|
|
services.AddEndpointsApiExplorer();
|
|
services.AddHttpsRedirection(options =>
|
|
{
|
|
options.HttpsPort = 2023; // The default HTTPS port
|
|
});
|
|
services.AddSwaggerGen(c =>
|
|
{
|
|
c.SwaggerDoc("v2", new OpenApiInfo
|
|
{
|
|
Version = "v2",
|
|
Title = "LLI API",
|
|
Description = "ASP.NET Core Web API",
|
|
//TermsOfService = new Uri("https://example.com/terms"),
|
|
Contact = new OpenApiContact
|
|
{
|
|
Name = "Rowell Soriano",
|
|
Email = string.Empty,
|
|
Url = new Uri("http://lloydlab.com/"),
|
|
},
|
|
License = new OpenApiLicense
|
|
{
|
|
Name = "Use under LLI",
|
|
Url = new Uri("http://lloydlab.com/"),
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
private static void AddIdentityServices(IServiceCollection services)
|
|
{
|
|
services.AddIdentity<ApplicationUser, IdentityRole>()
|
|
.AddEntityFrameworkStores<NonInventoryDbContext>()
|
|
.AddDefaultTokenProviders();
|
|
|
|
services.AddScoped<UserClaimsManager>();
|
|
}
|
|
|
|
private static void AddDbContexts(WebApplicationBuilder builder, IServiceCollection services)
|
|
{
|
|
var defaultConn = builder.Configuration.GetConnectionString("DefaultConnection");
|
|
var localConn = builder.Configuration.GetConnectionString("LocalPurchConn");
|
|
|
|
services.AddDbContext<NonInventoryDbContext>(options =>
|
|
options.UseSqlServer(defaultConn, sql =>
|
|
{
|
|
sql.EnableRetryOnFailure(5, TimeSpan.FromHours(2), null);
|
|
sql.CommandTimeout(20);
|
|
}));
|
|
services.AddDbContext<PurchLocalDbContext>(options =>
|
|
options.UseSqlServer(localConn, sql =>
|
|
{
|
|
sql.EnableRetryOnFailure(5, TimeSpan.FromHours(2), null);
|
|
sql.CommandTimeout(20);
|
|
}));
|
|
}
|
|
|
|
private static void AddMvcServices(IServiceCollection services)
|
|
{
|
|
services.AddMvc().AddJsonOptions(options =>
|
|
{
|
|
options.JsonSerializerOptions.WriteIndented = true;
|
|
});
|
|
}
|
|
|
|
private static void AddAuthenticationServices(WebApplicationBuilder builder, IServiceCollection services)
|
|
{
|
|
services.AddAuthentication(options =>
|
|
{
|
|
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
})
|
|
.AddJwtBearer(options =>
|
|
{
|
|
options.SaveToken = true;
|
|
options.RequireHttpsMetadata = false;
|
|
options.TokenValidationParameters = new TokenValidationParameters()
|
|
{
|
|
ValidateIssuer = true,
|
|
ValidateAudience = true,
|
|
ValidAudience = builder.Configuration["JWT:ValidAudience"],
|
|
ValidIssuer = builder.Configuration["JWT:ValidIssuer"],
|
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["JWT:Secret"] ?? "N/A"))
|
|
};
|
|
});
|
|
}
|
|
|
|
private static void AddCorsServices(IServiceCollection services)
|
|
{
|
|
services.AddCors(options =>
|
|
{
|
|
options.AddPolicy("AllowAnyOrigin",
|
|
builder =>
|
|
{
|
|
builder.AllowAnyOrigin()
|
|
.AllowAnyMethod()
|
|
.AllowAnyHeader();
|
|
});
|
|
});
|
|
}
|
|
|
|
private static void AddOtherServices(IServiceCollection services)
|
|
{
|
|
services.AddMemoryCache();
|
|
services.AddScoped<IRoleAuthorizationCache, RoleAuthorizationCache>();
|
|
services.AddScoped<ITransactionFacade, TransactionFacade>();
|
|
services.AddScoped<IDepartment, Department>();
|
|
services.AddScoped<IAttachment, Domain.Services.Account.Attachment>();
|
|
services.AddScoped<IItem, Domain.Services.Items.Item>();
|
|
services.AddScoped<IPRequest, Domain.Services.PR.PRequest>();
|
|
services.AddScoped<ICanvass, Canvass>();
|
|
services.AddScoped<IRIS, RIS>();
|
|
services.AddScoped<IMRS, MRS>();
|
|
services.AddScoped<IReportDataService, ReportDataService>();
|
|
services.AddScoped<IInventoryReports, InventoryReports>();
|
|
#region Automation using LLM
|
|
services.AddHttpClient<SupplierSearchService>();
|
|
#endregion
|
|
|
|
services.AddScoped<IRR, RR>();
|
|
services.AddScoped<IReceiving, Receiving>();
|
|
services.AddScoped <ISMTP, SMTP>();
|
|
services.AddScoped<IInventory, Inventory>();
|
|
services.AddScoped<IControllerAccess, Domain.Services.Account.ControllerAccess>();
|
|
services.AddScoped<ErrorMessageService>();
|
|
services.AddTransient<IPurchaseOrder, PurchaseOrder>();
|
|
services.AddScoped<IForgotPassword,Domain.Services.Account.ForgotPassword>();
|
|
services.AddScoped<IAccount, Account>();
|
|
services.AddScoped<SMTPHelper>();
|
|
services.AddScoped<EmailValidationService>();
|
|
}
|
|
}
|
|
}
|