Stashbox by Peter Csajtai

<PackageReference Include="Stashbox" Version="3.1.0-preview-526" />

 BaseFluentConfigurator<TConfigurator>

public class BaseFluentConfigurator<TConfigurator> : RegistrationConfiguration, IBaseFluentConfigurator<TConfigurator> where TConfigurator : BaseFluentConfigurator<TConfigurator>
Represents the base of the fluent registration api.
using Stashbox.Configuration; using Stashbox.Entity; using Stashbox.Exceptions; using Stashbox.Utils; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; namespace Stashbox.Registration.Fluent { public class BaseFluentConfigurator<TConfigurator> : RegistrationConfiguration, IBaseFluentConfigurator<TConfigurator> where TConfigurator : BaseFluentConfigurator<TConfigurator> { internal BaseFluentConfigurator(Type serviceType, Type implementationType) : base(serviceType, implementationType) { } public TConfigurator WithInjectionParameters(params InjectionParameter[] injectionParameters) { int num = injectionParameters.Length; for (int i = 0; i < num; i++) { AddInjectionParameter(injectionParameters[i]); } return (TConfigurator)this; } public TConfigurator WithInjectionParameter(string name, object value) { AddInjectionParameter(new InjectionParameter { Name = name, Value = value }); return (TConfigurator)this; } public TConfigurator WithAutoMemberInjection(Rules.AutoMemberInjectionRules rule = Rules.AutoMemberInjectionRules.PropertiesWithPublicSetter, Func<MemberInfo, bool> filter = null) { base.Context.AutoMemberInjectionEnabled = true; base.Context.AutoMemberInjectionRule = rule; base.Context.MemberInjectionFilter = filter; return (TConfigurator)this; } public TConfigurator WithConstructorSelectionRule(Func<IEnumerable<ConstructorInfo>, IEnumerable<ConstructorInfo>> rule) { base.Context.ConstructorSelectionRule = rule; return (TConfigurator)this; } public TConfigurator WithConstructorByArgumentTypes(params Type[] argumentTypes) { ConstructorInfo constructorByTypes = base.ImplementationType.GetConstructorByTypes(argumentTypes); if ((object)constructorByTypes == null) ThrowConstructorNotFoundException(base.ImplementationType, argumentTypes); base.Context.SelectedConstructor = constructorByTypes; return (TConfigurator)this; } public TConfigurator WithConstructorByArguments(params object[] arguments) { Type[] array = Enumerable.ToArray<Type>(Enumerable.Select<object, Type>((IEnumerable<object>)arguments, (Func<object, Type>)((object arg) => arg.GetType()))); ConstructorInfo constructorByTypes = base.ImplementationType.GetConstructorByTypes(array); if ((object)constructorByTypes == null) ThrowConstructorNotFoundException(base.ImplementationType, array); base.Context.SelectedConstructor = constructorByTypes; base.Context.ConstructorArguments = arguments; return (TConfigurator)this; } public TConfigurator InjectMember(string memberName, object dependencyName = null) { base.Context.InjectionMemberNames.Add(memberName, dependencyName); return (TConfigurator)this; } public TConfigurator WithDependencyBinding(Type dependencyType, object dependencyName) { Shield.EnsureNotNull<Type>(dependencyType, "dependencyType"); Shield.EnsureNotNull<object>(dependencyName, "dependencyName"); base.Context.DependencyBindings.Add(dependencyType, dependencyName); return (TConfigurator)this; } public TConfigurator WithDependencyBinding(string parameterName, object dependencyName) { Shield.EnsureNotNull<string>(parameterName, "parameterName"); Shield.EnsureNotNull<object>(dependencyName, "dependencyName"); base.Context.DependencyBindings.Add(parameterName, dependencyName); return (TConfigurator)this; } public TConfigurator WithoutDisposalTracking() { base.Context.IsLifetimeExternallyOwned = true; return (TConfigurator)this; } public TConfigurator ReplaceExisting() { base.Context.ReplaceExistingRegistration = true; return (TConfigurator)this; } public TConfigurator WithoutFactoryCache() { base.Context.FactoryCacheDisabled = true; return (TConfigurator)this; } private void AddInjectionParameter(InjectionParameter injectionParameter) { ((List<InjectionParameter>)base.Context.InjectionParameters).Add(injectionParameter); } private void ThrowConstructorNotFoundException(Type type, params Type[] argTypes) { if (argTypes.Length == 0) throw new ConstructorNotFoundException(type, (Exception)null); if (argTypes.Length == 1) throw new ConstructorNotFoundException(type, argTypes[0], null); throw new ConstructorNotFoundException(type, argTypes, null); } } }