FluentServiceConfigurator<TService, TImplementation, TConfigurator>
public class FluentServiceConfigurator<TService, TImplementation, TConfigurator> : FluentServiceConfigurator<TConfigurator>, IFluentCompositor<TImplementation, TConfigurator> where TImplementation : TService where TConfigurator : FluentServiceConfigurator<TService, TImplementation, TConfigurator>
Represents the generic fluent service registration api.
using Stashbox.Utils;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace Stashbox.Registration.Fluent
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(new byte[] {
0,
1
})]
public class FluentServiceConfigurator<TService, TImplementation, [System.Runtime.CompilerServices.Nullable(0)] TConfigurator> : FluentServiceConfigurator<TConfigurator>, IFluentCompositor<TImplementation, TConfigurator> where TService : class where TImplementation : class, TService 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 WithDependencyBinding<[System.Runtime.CompilerServices.Nullable(2)] TResult>(Expression<Func<TImplementation, TResult>> expression, [System.Runtime.CompilerServices.Nullable(2)] object dependencyName = null)
{
MemberExpression memberExpression = expression.Body as MemberExpression;
if (memberExpression == null)
throw new ArgumentException("The expression must be a member expression (Property or Field)", "expression");
RegistrationContext context = base.Context;
if (context.DependencyBindings == null)
context.DependencyBindings = new Dictionary<object, object>();
base.Context.DependencyBindings.Add((object)memberExpression.Member.Name, dependencyName);
return (TConfigurator)this;
}
public TConfigurator WithFinalizer(Action<TImplementation> finalizer)
{
Shield.EnsureNotNull<Action<TImplementation>>(finalizer, "finalizer");
base.Context.Finalizer = delegate(object o) {
finalizer((TImplementation)o);
};
return (TConfigurator)this;
}
public TConfigurator WithInitializer(Action<TImplementation, IDependencyResolver> initializer)
{
Shield.EnsureNotNull<Action<TImplementation, IDependencyResolver>>(initializer, "initializer");
base.Context.Initializer = initializer;
return (TConfigurator)this;
}
public TConfigurator WithAsyncInitializer(Func<TImplementation, IDependencyResolver, CancellationToken, Task> initializer)
{
Shield.EnsureNotNull<Func<TImplementation, IDependencyResolver, CancellationToken, Task>>(initializer, "initializer");
base.Context.AsyncInitializer = ((object o, IDependencyResolver r, CancellationToken t) => initializer((TImplementation)o, r, t));
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<[System.Runtime.CompilerServices.Nullable(2)] 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<[System.Runtime.CompilerServices.Nullable(2)] T1, [System.Runtime.CompilerServices.Nullable(2)] 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;
}
[System.Runtime.CompilerServices.NullableContext(2)]
[return: System.Runtime.CompilerServices.Nullable(1)]
public TConfigurator WithFactory<T1, T2, T3>([System.Runtime.CompilerServices.Nullable(1)] 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;
}
[System.Runtime.CompilerServices.NullableContext(2)]
[return: System.Runtime.CompilerServices.Nullable(1)]
public TConfigurator WithFactory<T1, T2, T3, T4>([System.Runtime.CompilerServices.Nullable(1)] 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;
}
[System.Runtime.CompilerServices.NullableContext(2)]
[return: System.Runtime.CompilerServices.Nullable(1)]
public TConfigurator WithFactory<T1, T2, T3, T4, T5>([System.Runtime.CompilerServices.Nullable(1)] 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;
}
}
}