Stashbox by Peter Csajtai

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

 BaseFluentConfigurator<TConfigurator>

public class BaseFluentConfigurator<TConfigurator> : RegistrationConfiguration where TConfigurator : BaseFluentConfigurator<TConfigurator>
Represents the base of the fluent registration api.
using Stashbox.Configuration; 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 where TConfigurator : BaseFluentConfigurator<TConfigurator> { internal BaseFluentConfigurator(Type serviceType, Type implementationType) : base(serviceType, implementationType) { } public TConfigurator WithInjectionParameters(params KeyValuePair<string, object>[] 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 KeyValuePair<string, object>(name, 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 constructorByArguments = base.ImplementationType.GetConstructorByArguments(argumentTypes); if (constructorByArguments == (ConstructorInfo)null) ThrowConstructorNotFoundException(base.ImplementationType, argumentTypes); base.Context.SelectedConstructor = constructorByArguments; 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 constructorByArguments = base.ImplementationType.GetConstructorByArguments(array); if (constructorByArguments == (ConstructorInfo)null) ThrowConstructorNotFoundException(base.ImplementationType, array); base.Context.SelectedConstructor = constructorByArguments; 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; } private void AddInjectionParameter(KeyValuePair<string, object> injectionParameter) { ((ExpandableArray<KeyValuePair<string, object>>)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); } } }