Skip to content

Commit

Permalink
Merge pull request #59 from NerosoftDev/develop
Browse files Browse the repository at this point in the history
Automatic set validator factory.
  • Loading branch information
Codespilot authored Dec 12, 2023
2 parents 8530e94 + 790aa25 commit 77dc50f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
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

0 comments on commit 77dc50f

Please sign in to comment.