-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAutofacDependencyScope.cs
More file actions
81 lines (75 loc) · 3.39 KB
/
AutofacDependencyScope.cs
File metadata and controls
81 lines (75 loc) · 3.39 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
// =================================================================================================================================
// Copyright (c) RapidField LLC. Licensed under the MIT License. See LICENSE.txt in the project root for license information.
// =================================================================================================================================
using Autofac;
using System;
using System.Diagnostics;
namespace RapidField.SolidInstruments.InversionOfControl.Autofac
{
/// <summary>
/// Represents a shared initialization and disposal scope for Autofac container-resolved objects.
/// </summary>
public sealed class AutofacDependencyScope : DependencyScope<ILifetimeScope>
{
/// <summary>
/// Initializes a new instance of the <see cref="AutofacDependencyScope" /> class.
/// </summary>
/// <param name="sourceScope">
/// The underlying scope.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="sourceScope" /> is <see langword="null" />.
/// </exception>
[DebuggerHidden]
internal AutofacDependencyScope(ILifetimeScope sourceScope)
: base(sourceScope)
{
return;
}
/// <summary>
/// Creates a new child initialization and disposal scope for the current <see cref="AutofacDependencyScope" />.
/// </summary>
/// <param name="sourceScope">
/// The underlying scope.
/// </param>
/// <returns>
/// A new child initialization and disposal scope for the current <see cref="AutofacDependencyScope" />.
/// </returns>
protected override IDependencyScope CreateChildScope(ILifetimeScope sourceScope) => new AutofacDependencyScope(sourceScope.BeginLifetimeScope());
/// <summary>
/// Releases all resources consumed by the current <see cref="AutofacDependencyScope" />.
/// </summary>
/// <param name="disposing">
/// A value indicating whether or not managed resources should be released.
/// </param>
protected sealed override void Dispose(Boolean disposing) => base.Dispose(disposing);
/// <summary>
/// Requests an object of specified type from the associated container for the current
/// <see cref="DependencyScope{TScope}" />.
/// </summary>
/// <param name="sourceScope">
/// The underlying scope.
/// </param>
/// <param name="type">
/// The type of the object to resolve.
/// </param>
/// <returns>
/// An object of specified type from the associated container.
/// </returns>
protected override Object Resolve(ILifetimeScope sourceScope, Type type) => sourceScope.Resolve(type);
/// <summary>
/// Requests an object of specified type from the associated container for the current
/// <see cref="AutofacDependencyScope" />.
/// </summary>
/// <param name="sourceScope">
/// The underlying scope.
/// </param>
/// <typeparam name="T">
/// The type of the object to resolve.
/// </typeparam>
/// <returns>
/// An object of specified type from the associated container.
/// </returns>
protected override T Resolve<T>(ILifetimeScope sourceScope) => sourceScope.Resolve<T>();
}
}