-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathResolverConfigExtensions.cs
64 lines (50 loc) · 2.29 KB
/
ResolverConfigExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
namespace Smart.Data.Accessor.Resolver;
using Smart.Converter;
using Smart.Data.Accessor.Dialect;
using Smart.Data.Accessor.Engine;
using Smart.Data.Accessor.Resolver.Components;
using Smart.Data.Accessor.Resolver.Handlers;
using Smart.Data.Accessor.Selectors;
using Smart.Resolver;
public static class ResolverConfigExtensions
{
public static ResolverConfig UseDataAccessor(this ResolverConfig config)
{
return config.UseDataAccessorInternal(null);
}
public static ResolverConfig UseDataAccessor(this ResolverConfig config, Action<ExecuteEngineFactoryOptions> action)
{
return config.UseDataAccessorInternal(action);
}
private static ResolverConfig UseDataAccessorInternal(this ResolverConfig config, Action<ExecuteEngineFactoryOptions>? action)
{
var options = new ExecuteEngineFactoryOptions();
action?.Invoke(options);
config.Bind<ExecuteEngine>().ToMethod(r =>
{
var engineConfig = new ExecuteEngineConfig();
engineConfig.SetServiceProvider(new ServiceProviderAdapter(r));
if (options.TypeMapConfig is not null)
{
engineConfig.ConfigureTypeMap(options.TypeMapConfig);
}
if (options.TypeHandlersConfig is not null)
{
engineConfig.ConfigureTypeHandlers(options.TypeHandlersConfig);
}
if (options.ResultMapperFactoriesConfig is not null)
{
engineConfig.ConfigureResultMapperFactories(options.ResultMapperFactoriesConfig);
}
return engineConfig.ToEngine();
}).InSingletonScope();
config.Bind<DataAccessorFactory>().ToSelf().InSingletonScope();
config.Bind<IObjectConverter>().ToConstant(ObjectConverter.Default).InSingletonScope();
config.Bind<IMappingSelector>().To<MappingSelector>().InSingletonScope();
config.Bind<IMultiMappingSelector>().To<MultiMappingSelector>().InSingletonScope();
config.Bind<IEmptyDialect>().To<EmptyDialect>().InSingletonScope();
config.Bind<IDbProviderSelector>().To<ResolverDbProviderSelector>().InSingletonScope();
config.UseMissingHandler<AccessorMissingHandler>();
return config;
}
}