RegisterElement.cs
35 lines
| 1.2 KiB
| text/x-csharp
|
CSharpLexer
cin
|
r269 | using System; | |
using System.Xml.Serialization; | |||
using Unity.Lifetime; | |||
using Unity.Registration; | |||
namespace Implab.ServiceHost.Unity { | |||
[XmlRoot("register", Namespace = Schema.ContainerConfigurationNamespace)] | |||
cin
|
r277 | public class RegisterElement : TypeAbstractRegistration { | |
cin
|
r269 | ||
/// <summary> | |||
cin
|
r271 | /// An optional type which is registered as a service in the container, must be assignable to <see cref="ProvidesType">. | |
cin
|
r269 | /// </summary> | |
cin
|
r273 | [XmlAttribute("mapTo")] | |
public string MapToType { get; set; } | |||
cin
|
r269 | ||
cin
|
r270 | [XmlElement("constructor", typeof(ConstructorInjectionElement))] | |
[XmlElement("property", typeof(PropertyInjectionElement))] | |||
[XmlElement("method", typeof(MethodInjectionElement))] | |||
cin
|
r277 | public AbstractMemberInjection[] Injectors { get; set; } | |
public override Type GetImplementationType(Func<string, Type> resolver) { | |||
return string.IsNullOrEmpty(MapToType) ? null : resolver(MapToType); | |||
} | |||
cin
|
r272 | ||
cin
|
r277 | public override void Visit(TypeRegistrationBuilder builder) { | |
if(Injectors != null) | |||
foreach(var injector in Injectors) | |||
injector.Visit(builder); | |||
cin
|
r272 | } | |
cin
|
r277 | ||
cin
|
r269 | } | |
} |