FluentServiceConfigurator<TService, TImplementation, TConfigurator>
public class FluentServiceConfigurator<TService, TImplementation, TConfigurator> : FluentServiceConfigurator<TConfigurator>, IFluentCompositor<TImplementation, TConfigurator> where TConfigurator : FluentServiceConfigurator<TService, TImplementation, TConfigurator>
Represents the generic fluent service registration api.
using System;
using System.Linq.Expressions;
namespace Stashbox.Registration.Fluent
{
public class FluentServiceConfigurator<TService, TImplementation, TConfigurator> : FluentServiceConfigurator<TConfigurator>, IFluentCompositor<TImplementation, TConfigurator> where TConfigurator : FluentServiceConfigurator<TService, TImplementation, TConfigurator>
{
internal FluentServiceConfigurator(Type serviceType, Type implementationType)
: base(serviceType, implementationType)
{
}
internal FluentServiceConfigurator(Type serviceType, Type implementationType, RegistrationContext registrationContext)
: base(serviceType, implementationType, registrationContext)
{
}
public TConfigurator InjectMember<TResult>(Expression<Func<TImplementation, TResult>> expression, object dependencyName = null)
{
MemberExpression memberExpression = expression.Body as MemberExpression;
if (memberExpression != null) {
base.Context.InjectionMemberNames.Add(memberExpression.Member.Name, dependencyName);
return (TConfigurator)this;
}
throw new ArgumentException("The expression must be a member expression (Property or Field)", "expression");
}
public TConfigurator WithFinalizer(Action<TImplementation> finalizer)
{
base.Context.Finalizer = finalizer;
return (TConfigurator)this;
}
public TConfigurator WithInitializer(Action<TImplementation, IDependencyResolver> initializer)
{
base.Context.Initializer = initializer;
return (TConfigurator)this;
}
public TConfigurator WithFactory(Func<TImplementation> singleFactory, bool isCompiledLambda = false)
{
base.Context.SingleFactory = singleFactory;
base.Context.IsFactoryDelegateACompiledLambda = isCompiledLambda;
return (TConfigurator)this;
}
public TConfigurator WithFactory(Func<IDependencyResolver, TImplementation> containerFactory, bool isCompiledLambda = false)
{
base.Context.ContainerFactory = containerFactory;
base.Context.IsFactoryDelegateACompiledLambda = isCompiledLambda;
return (TConfigurator)this;
}
}
}