-
-
Notifications
You must be signed in to change notification settings - Fork 146
/
SimpleInjectorDependencyResolver.cs
78 lines (67 loc) · 2.56 KB
/
SimpleInjectorDependencyResolver.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using SimpleInjector;
namespace Splat.SimpleInjector
{
/// <summary>
/// Simple Injector implementation for <see cref="IMutableDependencyResolver"/>.
/// </summary>
/// <seealso cref="Splat.IMutableDependencyResolver" />
public class SimpleInjectorDependencyResolver : IMutableDependencyResolver
{
private Container _container;
/// <summary>
/// Initializes a new instance of the <see cref="SimpleInjectorDependencyResolver"/> class.
/// </summary>
/// <param name="container">The container.</param>
public SimpleInjectorDependencyResolver(Container container)
{
_container = container;
}
/// <inheritdoc />
public object GetService(Type serviceType, string contract = null) => _container.GetInstance(serviceType);
/// <inheritdoc />
public IEnumerable<object> GetServices(Type serviceType, string contract = null) =>
_container.GetAllInstances(serviceType);
/// <inheritdoc />
public void Register(Func<object> factory, Type serviceType, string contract = null) =>
_container.Register(serviceType, factory);
/// <inheritdoc />
public void UnregisterCurrent(Type serviceType, string contract = null)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public void UnregisterAll(Type serviceType, string contract = null)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public IDisposable ServiceRegistrationCallback(Type serviceType, string contract, Action<IDisposable> callback)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Disposes of the instance.
/// </summary>
/// <param name="disposing">Whether or not the instance is disposing.</param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
_container?.Dispose();
_container = null;
}
}
}
}