Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic set validator factory. #59

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions Source/Euonia.Mapping.Automapper/AutomapperModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ namespace Nerosoft.Euonia.Mapping;
/// </summary>
public class AutomapperModule : ModuleContextBase
{
private const string SERVICE_INJECTION_KEY = "automapper";

/// <inheritdoc />
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAutomapper();
context.Services.AddSingleton<ITypeAdapterFactory, AutomapperTypeAdapterFactory>();
}
{
context.Services.AddAutomapper();
context.Services.AddKeyedSingleton<ITypeAdapterFactory, AutomapperTypeAdapterFactory>(SERVICE_INJECTION_KEY);
}

/// <inheritdoc />
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var factory = context.ServiceProvider.GetService<ITypeAdapterFactory>();
if (factory != null)
{
TypeAdapterFactory.SetCurrent(factory);
}
}
{
var factory = context.ServiceProvider.GetKeyedService<ITypeAdapterFactory>(SERVICE_INJECTION_KEY);
if (factory != null)
{
TypeAdapterFactory.SetCurrent(factory);
}
}
}
24 changes: 13 additions & 11 deletions Source/Euonia.Mapping.Mapster/MapsterModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ namespace Nerosoft.Euonia.Mapping;
/// </summary>
public class MapsterModule : ModuleContextBase
{
private const string SERVICE_INJECTION_KEY = "mapster";

/// <inheritdoc />
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddMapster();
context.Services.AddSingleton<ITypeAdapterFactory, MapsterTypeAdapterFactory>();
}
{
context.Services.AddMapster();
context.Services.AddKeyedSingleton<ITypeAdapterFactory, MapsterTypeAdapterFactory>(SERVICE_INJECTION_KEY);
}

/// <inheritdoc />
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var factory = context.ServiceProvider.GetService<ITypeAdapterFactory>();
if (factory != null)
{
TypeAdapterFactory.SetCurrent(factory);
}
}
{
var factory = context.ServiceProvider.GetKeyedService<ITypeAdapterFactory>(SERVICE_INJECTION_KEY);
if (factory != null)
{
TypeAdapterFactory.SetCurrent(factory);
}
}
}
10 changes: 10 additions & 0 deletions Source/Euonia.Validation/ValidationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@ public override void ConfigureServices(ServiceConfigurationContext context)
context.Services.AddAutomaticRegistrar(new ValidationRegistrar());
context.Services.AddSingleton<IValidatorFactory, DefaultValidatorFactory>();
}

/// <inheritdoc/>
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var factory = context.ServiceProvider.GetService<IValidatorFactory>();
if (factory != null)
{
ValidatorFactory.SetCurrent(factory);
}
}
}
2 changes: 1 addition & 1 deletion project.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>8.1.8</Version>
<Version>8.1.9</Version>
<Authors>damon</Authors>
<Company>Nerosoft Ltd.</Company>
<Product>Euonia</Product>
Expand Down
Loading