|
1 |
| -namespace Inflow.Api.Extensions |
| 1 | +using DiyorMarket.Infrastructure.Persistence.Repositories; |
| 2 | +using DiyorMarket.Services; |
| 3 | +using Inflow.Domain.Intefaces.Services; |
| 4 | +using Inflow.Domain.Interfaces.Repositories; |
| 5 | +using Inflow.Domain.Interfaces.Services; |
| 6 | +using Inflow.Infrastructure; |
| 7 | +using Microsoft.EntityFrameworkCore; |
| 8 | +using Serilog; |
| 9 | + |
| 10 | +namespace Inflow.Api.Extensions |
2 | 11 | {
|
3 |
| - public class ConfigureServicesExtensions |
| 12 | + public static class ConfigureServicesExtensions |
4 | 13 | {
|
5 | 14 |
|
| 15 | + public static IServiceCollection ConfigureRepositories(this IServiceCollection services) |
| 16 | + { |
| 17 | + services.AddScoped<ICategoryRepository, CategoryRepository>(); |
| 18 | + services.AddScoped<IProductRepository, ProductRepository>(); |
| 19 | + services.AddScoped<ICommonRepository, CommonRepository>(); |
| 20 | + services.AddScoped<ICustomerRepository, CustomerRepository>(); |
| 21 | + services.AddScoped<ISaleRepository, SaleRepository>(); |
| 22 | + services.AddScoped<ISaleItemRepository, SaleItemRepository>(); |
| 23 | + services.AddScoped<ISupplierRepository, SupplierRepository>(); |
| 24 | + services.AddScoped<ISupplyRepository, SupplyRepository>(); |
| 25 | + services.AddScoped<ISupplyItemRepository, SupplyItemRepository>(); |
| 26 | + |
| 27 | + services.AddScoped<ICategoryService, CategoryService>(); |
| 28 | + services.AddScoped<IProductService, ProductService>(); |
| 29 | + services.AddScoped<ICustomerService, CustomerService>(); |
| 30 | + services.AddScoped<ISaleService, SaleService>(); |
| 31 | + services.AddScoped<ISaleItemService, SaleItemService>(); |
| 32 | + services.AddScoped<ISupplierService, SupplierService>(); |
| 33 | + services.AddScoped<ISupplyService, SupplyService>(); |
| 34 | + services.AddScoped<ISupplyItemService, SupplyItemService>(); |
| 35 | + services.AddScoped<IDashboardService, DashboardService>(); |
| 36 | + services.AddSingleton<IEmailSender, EmailSender>(); |
| 37 | + |
| 38 | + services.AddControllers() |
| 39 | + .AddNewtonsoftJson(options => |
| 40 | + options.SerializerSettings.ReferenceLoopHandling = |
| 41 | + Newtonsoft.Json.ReferenceLoopHandling.Ignore |
| 42 | + ); |
| 43 | + |
| 44 | + return services; |
| 45 | + } |
| 46 | + |
| 47 | + public static IServiceCollection ConfigureLogger(this IServiceCollection services) |
| 48 | + { |
| 49 | + Log.Logger = new LoggerConfiguration() |
| 50 | + .MinimumLevel.Information() |
| 51 | + .WriteTo.Console() |
| 52 | + .WriteTo.File("logs/logs.txt", rollingInterval: RollingInterval.Day) |
| 53 | + .WriteTo.File("logs/error_.txt", Serilog.Events.LogEventLevel.Error, rollingInterval: RollingInterval.Day) |
| 54 | + .CreateLogger(); |
| 55 | + |
| 56 | + return services; |
| 57 | + } |
| 58 | + |
| 59 | + public static IServiceCollection ConfigureDatabaseContext(this IServiceCollection services) |
| 60 | + { |
| 61 | + var builder = WebApplication.CreateBuilder(); |
| 62 | + |
| 63 | + services.AddDbContext<InflowDbContext>(options => |
| 64 | + options.UseSqlServer(builder.Configuration.GetConnectionString("DiyorMarketConection"))); |
| 65 | + |
| 66 | + return services; |
| 67 | + } |
6 | 68 | }
|
7 | 69 | }
|
| 70 | + |
0 commit comments