Rename service add method
This commit is contained in:
parent
27167ace1b
commit
c13f4ddda1
@ -32,7 +32,7 @@ builder.Services.AddIdentity<IdentityUser, IdentityRole>()
|
|||||||
|
|
||||||
builder.Services.AddScoped<IPricelistParser, ClosedXMLParser>()
|
builder.Services.AddScoped<IPricelistParser, ClosedXMLParser>()
|
||||||
.AddScoped<IProductTypePredicter, ProductTypePredicter>();
|
.AddScoped<IProductTypePredicter, ProductTypePredicter>();
|
||||||
builder.Services.AddModifiers();
|
builder.Services.AddProductParsers();
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
builder.Services.AddSwaggerGen(options =>
|
builder.Services.AddSwaggerGen(options =>
|
||||||
{
|
{
|
||||||
|
@ -11,7 +11,7 @@ public class TestServiceCollection
|
|||||||
public void CreateProvider()
|
public void CreateProvider()
|
||||||
{
|
{
|
||||||
var collection = new ServiceCollection();
|
var collection = new ServiceCollection();
|
||||||
collection.AddModifiers();
|
collection.AddProductParsers();
|
||||||
ServiceProvider = collection.BuildServiceProvider();
|
ServiceProvider = collection.BuildServiceProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ namespace RhSolutions.Parsers;
|
|||||||
|
|
||||||
public static class ParsersRegistration
|
public static class ParsersRegistration
|
||||||
{
|
{
|
||||||
public static void AddModifiers(this IServiceCollection services)
|
public static void AddProductParsers(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
var types = AppDomain.CurrentDomain.GetAssemblies()
|
var types = AppDomain.CurrentDomain.GetAssemblies()
|
||||||
.SelectMany(s => s.GetTypes())
|
.SelectMany(s => s.GetTypes())
|
||||||
@ -13,12 +13,12 @@ public static class ParsersRegistration
|
|||||||
|
|
||||||
foreach (Type t in types)
|
foreach (Type t in types)
|
||||||
{
|
{
|
||||||
string key = GetModifierKey(t);
|
string key = GetParserKey(t);
|
||||||
services.AddKeyedTransient(typeof(IProductParser), key, t);
|
services.AddKeyedTransient(typeof(IProductParser), key, t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetModifierKey(Type t)
|
private static string GetParserKey(Type t)
|
||||||
{
|
{
|
||||||
return t.GetCustomAttribute<ParserKey>()?.Value ?? string.Empty;
|
return t.GetCustomAttribute<ParserKey>()?.Value ?? string.Empty;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user