comparison Implab.ServiceHost/Unity/RegisterElement.cs @ 279:8714471e8d78 v3

Container configuration cleanup, RC2
author cin
date Fri, 04 May 2018 18:12:42 +0300
parents 963b17c275be
children
comparison
equal deleted inserted replaced
278:6691aff01de1 279:8714471e8d78
1 using System; 1 using System;
2 using System.Collections.Generic;
2 using System.Xml.Serialization; 3 using System.Xml.Serialization;
3 using Unity.Lifetime; 4 using Unity.Lifetime;
4 using Unity.Registration; 5 using Unity.Registration;
5 6
6 namespace Implab.ServiceHost.Unity { 7 namespace Implab.ServiceHost.Unity {
7 8
8 [XmlRoot("register", Namespace = Schema.ContainerConfigurationNamespace)] 9 [XmlRoot("register", Namespace = Schema.ContainerConfigurationNamespace)]
9 public class RegisterElement : TypeAbstractRegistration { 10 public class RegisterElement : AbstractRegistration, ITypeRegistration {
10 11
11 /// <summary> 12 /// <summary>
12 /// An optional type which is registered as a service in the container, must be assignable to <see cref="ProvidesType">. 13 /// An optional type which is registered as a service in the container, must be assignable to <see cref="ProvidesType">.
13 /// </summary> 14 /// </summary>
14 [XmlAttribute("mapTo")] 15 [XmlAttribute("mapTo")]
18 [XmlElement("constructor", typeof(ConstructorInjectionElement))] 19 [XmlElement("constructor", typeof(ConstructorInjectionElement))]
19 [XmlElement("property", typeof(PropertyInjectionElement))] 20 [XmlElement("property", typeof(PropertyInjectionElement))]
20 [XmlElement("method", typeof(MethodInjectionElement))] 21 [XmlElement("method", typeof(MethodInjectionElement))]
21 public AbstractMemberInjection[] Injectors { get; set; } 22 public AbstractMemberInjection[] Injectors { get; set; }
22 23
23 public override Type GetImplementationType(Func<string, Type> resolver) { 24 IEnumerable<ITypeMemberInjection> ITypeRegistration.MemberInjections {
24 return string.IsNullOrEmpty(MapToType) ? null : resolver(MapToType); 25 get {
26 return Injectors;
27 }
25 } 28 }
26 29
27 public override void Visit(TypeRegistrationBuilder builder) { 30 public Type GetImplementationType(ContainerBuilder builder) {
28 if(Injectors != null) 31 return builder.ResolveType(MapToType);
29 foreach(var injector in Injectors)
30 injector.Visit(builder);
31 } 32 }
32 33
33 34 public override void Visit(ContainerBuilder builder) {
35 builder.Visit(this);
36 }
34 } 37 }
35 38
36 } 39 }