Mercurial > pub > ImplabNet
comparison Implab.ServiceHost/Unity/ConfigurationContext.cs @ 272:9d1cca834b05 v3
preview version of Unity xml configuration
author | cin |
---|---|
date | Thu, 26 Apr 2018 03:14:54 +0300 |
parents | ade80d94dfb5 |
children |
comparison
equal
deleted
inserted
replaced
271:d4d437ec4483 | 272:9d1cca834b05 |
---|---|
6 namespace Implab.ServiceHost.Unity { | 6 namespace Implab.ServiceHost.Unity { |
7 using System.Linq; | 7 using System.Linq; |
8 using System.Reflection; | 8 using System.Reflection; |
9 using System.Text; | 9 using System.Text; |
10 using global::Unity; | 10 using global::Unity; |
11 using global::Unity.Registration; | |
11 using Implab.Xml; | 12 using Implab.Xml; |
12 using static Trace<ConfigurationContext>; | 13 using static Trace<ConfigurationContext>; |
13 | 14 |
14 public class ConfigurationContext { | 15 public class ConfigurationContext { |
15 | 16 |
16 readonly TypeResolver m_resolver; | 17 readonly TypeResolver m_resolver; |
17 | 18 |
18 | 19 readonly UnityContainer m_container; |
19 | 20 |
20 readonly UnityContainer m_container; | |
21 | |
22 public ConfigurationContext(UnityContainer container) { | 21 public ConfigurationContext(UnityContainer container) { |
23 m_container = container ?? new UnityContainer(); | 22 m_container = container ?? new UnityContainer(); |
24 m_resolver = new TypeResolver(); | 23 m_resolver = new TypeResolver(); |
25 } | 24 } |
26 | 25 |
27 | 26 |
28 public Type Resolve(string typeReference) { | 27 public Type Resolve(string typeReference) { |
29 return m_resolver.Resolve(TypeReference.Parse(typeReference)); | 28 return m_resolver.Resolve(TypeReference.Parse(typeReference)); |
30 } | 29 } |
31 | 30 |
32 internal void Visit(AbstractRegistration descriptor) { | 31 internal void Visit(RegisterElement descriptor) { |
33 | 32 var registrationContext = new RegistrationContext(m_resolver, descriptor.ProvidesType, descriptor.ImplementationType); |
33 | |
34 if (descriptor.Injectors != null) { | |
35 foreach (var injector in descriptor.Injectors) { | |
36 injector.Visit(registrationContext); | |
37 } | |
38 } | |
39 | |
40 m_container.RegisterType( | |
41 registrationContext.RegistrationType, | |
42 registrationContext.ImplementationType, | |
43 descriptor.Name, | |
44 descriptor.Lifetime?.GetLifetimeManager(this), | |
45 registrationContext.Injections | |
46 ); | |
47 | |
34 } | 48 } |
35 | 49 |
36 internal void Visit(NamespaceElement namespaceElement) { | 50 internal void Visit(NamespaceElement namespaceElement) { |
37 m_resolver.AddNamespace(namespaceElement.Name); | 51 m_resolver.AddNamespace(namespaceElement.Name); |
38 } | 52 } |