Stashbox by Peter Csajtai

<PackageReference Include="Stashbox" Version="3.6.3-preview-640" />

 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 Stashbox.Utils; 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) { } [Obsolete("Use WithDependencyBinding() instead.")] public TConfigurator InjectMember<TResult>(Expression<Func<TImplementation, TResult>> expression, object dependencyName = null) { return WithDependencyBinding(expression, dependencyName); } public TConfigurator WithDependencyBinding<TResult>(Expression<Func<TImplementation, TResult>> expression, object dependencyName = null) { MemberExpression memberExpression = expression.Body as MemberExpression; if (memberExpression != null) { base.Context.DependencyBindings.Add((object)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> factory, bool isCompiledLambda = false) { SetFactory(factory, isCompiledLambda, typeof(TImplementation)); return (TConfigurator)this; } public TConfigurator WithFactory(Func<IDependencyResolver, TImplementation> factory, bool isCompiledLambda = false) { SetFactory(factory, isCompiledLambda, Constants.ResolverType, typeof(TImplementation)); return (TConfigurator)this; } public TConfigurator WithFactory<T1>(Func<T1, TImplementation> factory, bool isCompiledLambda = false) { base.SetFactory((Delegate)factory, isCompiledLambda, new Type[2] { typeof(T1), typeof(TImplementation) }); return (TConfigurator)this; } public TConfigurator WithFactory<T1, T2>(Func<T1, T2, TImplementation> factory, bool isCompiledLambda = false) { base.SetFactory((Delegate)factory, isCompiledLambda, new Type[3] { typeof(T1), typeof(T2), typeof(TImplementation) }); return (TConfigurator)this; } public TConfigurator WithFactory<T1, T2, T3>(Func<T1, T2, T3, TImplementation> factory, bool isCompiledLambda = false) { base.SetFactory((Delegate)factory, isCompiledLambda, new Type[4] { typeof(T1), typeof(T2), typeof(T3), typeof(TImplementation) }); return (TConfigurator)this; } public TConfigurator WithFactory<T1, T2, T3, T4>(Func<T1, T2, T3, T4, TImplementation> factory, bool isCompiledLambda = false) { base.SetFactory((Delegate)factory, isCompiledLambda, new Type[5] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(TImplementation) }); return (TConfigurator)this; } public TConfigurator WithFactory<T1, T2, T3, T4, T5>(Func<T1, T2, T3, T4, T5, TImplementation> factory, bool isCompiledLambda = false) { base.SetFactory((Delegate)factory, isCompiledLambda, new Type[6] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(TImplementation) }); return (TConfigurator)this; } } }