##// END OF EJS Templates
Working on Implab.Diagnostics
Working on Implab.Diagnostics

File last commit:

r279:8714471e8d78 v3
r286:67ebcfd7d1c8 v3
Show More
FactoryActivator.cs
62 lines | 2.1 KiB | text/x-csharp | CSharpLexer
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278 using System;
cin
Container configuration cleanup, RC2
r279 using System.Collections.Generic;
using System.Reflection;
using Implab.Components;
using Unity;
using Unity.Injection;
using Unity.Lifetime;
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278
namespace Implab.ServiceHost.Unity {
cin
Container configuration cleanup, RC2
r279 public class FactoryActivator : ITypeRegistration {
class FactoryInjector : ITypeMemberInjection {
public InjectionFactory Factory { get; set; }
public void Visit(TypeRegistrationBuilder builder) {
builder.AddInjectionMember(Factory);
}
}
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278
public Type FactoryType { get; set; }
public string FactoryName { get; set; }
cin
Container configuration cleanup, RC2
r279 public Type RegistrationType { get; set; }
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278
cin
Container configuration cleanup, RC2
r279 public LifetimeManager Lifetime { get; set; }
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278
cin
Container configuration cleanup, RC2
r279 public IEnumerable<ITypeMemberInjection> MemberInjections {
get {
yield return new FactoryInjector {
Factory = (InjectionFactory)GetType()
.GetMethod(nameof(CreateInjectionFactory), BindingFlags.Static | BindingFlags.NonPublic)
.MakeGenericMethod(FactoryType, RegistrationType)
.Invoke(null, new [] { FactoryName })
};
}
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278 }
cin
Container configuration cleanup, RC2
r279 public string Name { get; set; }
public Type GetRegistrationType(ContainerBuilder builder) {
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278 return RegistrationType;
}
cin
Container configuration cleanup, RC2
r279 public LifetimeManager GetLifetime(ContainerBuilder builder) {
return Lifetime;
}
public Type GetImplementationType(ContainerBuilder builder) {
return null;
}
/// <summary>
/// Указывает зависимость, реализующую интерфейс <see cref="IFactory{TObj}"/>,
/// которая будет использоваться в качестве фабрики для создания объектов
/// </summary>
/// <param name="dependencyName"></param>
static InjectionFactory CreateInjectionFactory<TFac, TObj>(string dependencyName) where TFac : IFactory<TObj> {
return new InjectionFactory(c => c.Resolve<TFac>(dependencyName).Create());
}
cin
Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)...
r278 }
}