-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDependencyModule.cs
More file actions
86 lines (80 loc) · 3.45 KB
/
DependencyModule.cs
File metadata and controls
86 lines (80 loc) · 3.45 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// =================================================================================================================================
// Copyright (c) RapidField LLC. Licensed under the MIT License. See LICENSE.txt in the project root for license information.
// =================================================================================================================================
using Microsoft.Extensions.Configuration;
using RapidField.SolidInstruments.Core.ArgumentValidation;
using System;
using System.Diagnostics;
namespace RapidField.SolidInstruments.InversionOfControl
{
/// <summary>
/// Encapsulates container configuration for a group of related dependencies.
/// </summary>
/// <remarks>
/// <see cref="DependencyModule{TConfigurator}" /> is the default implementation of
/// <see cref="IDependencyModule{TConfigurator}" />.
/// </remarks>
/// <typeparam name="TConfigurator">
/// The type of the object that configures containers.
/// </typeparam>
public abstract class DependencyModule<TConfigurator> : IDependencyModule<TConfigurator>
where TConfigurator : class, new()
{
/// <summary>
/// Initializes a new instance of the <see cref="DependencyModule{TConfigurator}" /> class.
/// </summary>
/// <param name="applicationConfiguration">
/// Configuration information for the application.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="applicationConfiguration" /> is <see langword="null" />.
/// </exception>
protected DependencyModule(IConfiguration applicationConfiguration)
{
ApplicationConfiguration = applicationConfiguration.RejectIf().IsNull(nameof(applicationConfiguration)).TargetArgument;
}
/// <summary>
/// Configures the module.
/// </summary>
/// <param name="configurator">
/// An object that configures containers.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="configurator" /> is <see langword="null" />.
/// </exception>
/// <exception cref="ContainerConfigurationException">
/// An exception was raised while attempting to configure the container.
/// </exception>
public void Configure(TConfigurator configurator)
{
configurator = configurator.RejectIf().IsNull(nameof(configurator));
try
{
Configure(configurator, ApplicationConfiguration);
}
catch (ContainerConfigurationException)
{
throw;
}
catch (Exception exception)
{
throw new ContainerConfigurationException(exception);
}
}
/// <summary>
/// Configures the module.
/// </summary>
/// <param name="configurator">
/// An object that configures containers.
/// </param>
/// <param name="applicationConfiguration">
/// Configuration information for the application.
/// </param>
protected abstract void Configure(TConfigurator configurator, IConfiguration applicationConfiguration);
/// <summary>
/// Represents configuration information for the application.
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly IConfiguration ApplicationConfiguration;
}
}