FluentServiceConfigurator<TService, TImplementation, TConfigurator>
public class FluentServiceConfigurator<TService, TImplementation, TConfigurator> : BaseFluentServiceConfigurator<TService, TImplementation, TConfigurator> where TConfigurator : FluentServiceConfigurator<TService, TImplementation, TConfigurator>
Represents the generic fluent service registration api.
using Stashbox.Utils.Data;
using System;
using System.Linq;
namespace Stashbox.Registration.Fluent
{
public class FluentServiceConfigurator<TService, TImplementation, TConfigurator> : BaseFluentServiceConfigurator<TService, TImplementation, TConfigurator> where TConfigurator : FluentServiceConfigurator<TService, TImplementation, TConfigurator>
{
internal FluentServiceConfigurator(Type serviceType, Type implementationType)
: base(serviceType, implementationType)
{
}
public TConfigurator WithInstance(TService instance, bool wireUp = false)
{
base.Context.ExistingInstance = instance;
base.Context.IsWireUp = wireUp;
base.ImplementationType = instance.GetType();
return (TConfigurator)this;
}
public TConfigurator WithName(object name)
{
base.Context.Name = name;
return (TConfigurator)this;
}
public TConfigurator DefinesScope(object scopeName = null)
{
base.Context.DefinedScopeName = (scopeName ?? base.ImplementationType);
return (TConfigurator)this;
}
public TConfigurator AsImplementedTypes()
{
base.Context.AdditionalServiceTypes = EnumerableExtensions.AsExpandableArray<Type>(Enumerable.Concat<Type>(base.ImplementationType.GetRegisterableInterfaceTypes(), base.ImplementationType.GetRegisterableBaseTypes()));
return (TConfigurator)this;
}
public TConfigurator AsServiceAlso<TAdditionalService>()
{
return this.AsServiceAlso(typeof(TAdditionalService));
}
public TConfigurator AsServiceAlso(Type serviceType)
{
if (!base.ImplementationType.Implements(serviceType))
throw new ArgumentException(string.Format("The implementation type {0} does not implement the given service type {1}.", new object[2] {
base.ImplementationType,
serviceType
}));
((ExpandableArray<Type>)base.Context.AdditionalServiceTypes).Add(serviceType);
return (TConfigurator)this;
}
}
}