Files
XLIMS/XLIMS.SERVICES/XLimsServicesDI.cs
Курнат Андрей f0e11d6379 first edit
2026-01-31 16:11:36 +03:00

50 lines
2.0 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Configuration;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.IO;
using XLIMS.DATA.Models;
using XLIMS.CONTRACT;
using XLIMS.SERVICES;
namespace Microsoft.Extensions.DependencyInjection
{
public static class XLimsServicesDI
{
public static IServiceCollection AddXLimsServices(this IServiceCollection services)
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();
// Регистрируем DbContext с использованием строки из конфига
services.AddDbContext<LimsdbContext>(options =>
{
var connectionString = configuration.GetConnectionString("DefaultConnection");
options.UseSqlServer(connectionString);
// Опционально: логирование запросов в Debug
// options.LogTo(Console.WriteLine, LogLevel.Information);
});
// Остальные сервисы
// Фасад
services.AddScoped<ILimsService, LimsService>();
// Сервисы
services.AddSingleton<IDialogService, DialogService>();
// ViewModel'и
services.AddTransient<XLIMS.PSV.ViewModels.MainViewModel>();
services.AddTransient<XLIMS.SP.ViewModels.MainViewModel>();
services.AddTransient<XLIMS.TPRZ.ViewModels.MainViewModel>();
services.AddTransient<XLIMS.DEV.ViewModels.MainViewModel>();
// Сохраняем конфигурацию (если понадобится в других местах)
services.AddSingleton<IConfiguration>(configuration);
return services;
}
}
}