Вынести класс роли в отдельный файл

***
- Вынес класс роли в отдельный файл.
- Вынес подключение сервисов в метод расширения.
***
parent 87ee13bc
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PhoneStore.Models;
using PhoneStore.Services;
using PhoneStore.Services.Abstractions;
namespace PhoneStore.Helpers
{
public static class ServiceConnector
{
public static void AddApplicationServices(this IServiceCollection services, IConfiguration configuration)
{
services.AddScoped<IBasketService, BasketService>();
services.AddTransient<UploadService>();
services.AddTransient<IDefaultPhoneImagePathProvider>(_ =>
new DefaultPhoneImagePathProvider(configuration["PathToDefaultAvatar:Path"]));
services.AddTransient<IPhoneService, PhoneService>();
// services.AddTransient<IUserService, UserService>();
services.AddTransient<IUsersSortService, UsersSortService>();
services.AddTransient<IUsersFilter, UsersFilter>();
services.AddTransient<IPaginationService<User>, PaginationService<User>>();
}
}
}
\ No newline at end of file
using Microsoft.AspNetCore.Identity;
namespace PhoneStore.Models
{
public class Role : IdentityRole<int>
{
public Role() : base()
{
}
public Role(string roleName) : base(roleName)
{
}
}
}
\ No newline at end of file
...@@ -7,15 +7,4 @@ namespace PhoneStore.Models ...@@ -7,15 +7,4 @@ namespace PhoneStore.Models
public string Name { get; set; } public string Name { get; set; }
public int Age { get; set; } public int Age { get; set; }
} }
public class ApplicationRole : IdentityRole<int>
{
public ApplicationRole() : base()
{
}
public ApplicationRole(string roleName) : base(roleName)
{
}
}
} }
\ No newline at end of file
...@@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore; ...@@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using PhoneStore.Helpers;
using PhoneStore.Models; using PhoneStore.Models;
using PhoneStore.Services; using PhoneStore.Services;
using PhoneStore.Services.Abstractions; using PhoneStore.Services.Abstractions;
...@@ -27,15 +28,7 @@ namespace PhoneStore ...@@ -27,15 +28,7 @@ namespace PhoneStore
string connection = Configuration.GetConnectionString("DefaultConnection"); string connection = Configuration.GetConnectionString("DefaultConnection");
services.AddDbContext<MobileContext>(options => options.UseNpgsql(connection)); services.AddDbContext<MobileContext>(options => options.UseNpgsql(connection));
services.AddControllersWithViews(); services.AddControllersWithViews();
services.AddScoped<IBasketService, BasketService>(); services.AddApplicationServices(Configuration);
services.AddTransient<UploadService>();
services.AddTransient<IDefaultPhoneImagePathProvider>(_ =>
new DefaultPhoneImagePathProvider(Configuration["PathToDefaultAvatar:Path"]));
services.AddTransient<IPhoneService, PhoneService>();
// services.AddTransient<IUserService, UserService>();
services.AddTransient<IUsersSortService, UsersSortService>();
services.AddTransient<IUsersFilter, UsersFilter>();
services.AddTransient<IPaginationService<User>, PaginationService<User>>();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment