-
Notifications
You must be signed in to change notification settings - Fork 1
/
IocResolver.cs
48 lines (44 loc) · 1.39 KB
/
IocResolver.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
using Autofac;
using ServiceAnt.Infrastructure.Dependency;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ServiceAnt.IocInstaller.Autofac
{
/// <summary>
/// IocResolver
/// </summary>
public class IocResolver : IIocResolver
{
private readonly IComponentContext _componentContext;
/// <summary>
/// Constructor
/// </summary>
/// <param name="componentContext"></param>
public IocResolver(IComponentContext componentContext)
{
_componentContext = componentContext;
}
/// <summary>
/// Releases a pre-resolved object. See Resolve methods.
/// </summary>
/// <param name="obj">Object to be released</param>
public void Release(object obj)
{
// AutoFac is no need to release object
}
/// <summary>
/// Gets an object from IOC container.
/// Returning object must be Released (see <see cref="Release"/>) after usage.
/// </summary>
/// <typeparam name="T">Type of the object to cast</typeparam>
/// <param name="type">Type of the object to resolve</param>
/// <returns>The object instance</returns>
public T Resolve<T>(Type type)
{
return (T)_componentContext.Resolve(type);
}
}
}