forked from dotnetcore/AspectCore-Framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLightInjectServiceResolver.cs
More file actions
41 lines (36 loc) · 1.11 KB
/
Copy pathLightInjectServiceResolver.cs
File metadata and controls
41 lines (36 loc) · 1.11 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
using System;
using System.Collections.Generic;
using System.Text;
using AspectCore.DynamicProxy;
using AspectCore.DependencyInjection;
using LightInject;
namespace AspectCore.Extensions.LightInject
{
[NonAspect]
public class LightInjectServiceResolver : IServiceResolver
{
private readonly IServiceFactory _serviceFactory;
private bool _isDisposed = false;
public LightInjectServiceResolver(IServiceFactory serviceFactory)
{
_serviceFactory = serviceFactory;
}
public object GetService(Type serviceType)
{
return _serviceFactory.TryGetInstance(serviceType);
}
public void Dispose()
{
if (_isDisposed) return;
_isDisposed = true;
// To avoid dispose more than one time
// And this code block must be before "Dispose"
if (_serviceFactory is IDisposable disposable)
disposable.Dispose();
}
public object Resolve(Type serviceType)
{
return _serviceFactory.TryGetInstance(serviceType);
}
}
}