RegistrationConfiguration
Represents the collected configuration options of a registration.
using System;
using System.Runtime.CompilerServices;
namespace Stashbox.Registration.Fluent
{
public class RegistrationConfiguration
{
public Type ServiceType { get; }
public Type ImplementationType { get; set; }
internal RegistrationContext Context { get; }
internal RegistrationConfiguration(Type serviceType, Type implementationType)
: this(serviceType, implementationType, new RegistrationContext())
{
}
internal RegistrationConfiguration(Type serviceType, Type implementationType, RegistrationContext context)
{
ServiceType = serviceType;
ImplementationType = implementationType;
Context = context;
}
internal bool TypeMapIsValid(out string error)
{
error = null;
if ((object)Context.Factory != null)
return true;
DefaultInterpolatedStringHandler val = default(DefaultInterpolatedStringHandler);
if (!ImplementationType.IsResolvableType()) {
val..ctor(94, 1);
val.AppendLiteral("The type ");
val.AppendFormatted<Type>(ImplementationType);
val.AppendLiteral(" could not be resolved. It's probably an interface, abstract class or primitive type.");
error = val.ToStringAndClear();
return false;
}
if (ImplementationType.Implements(ServiceType))
return true;
val..ctor(47, 2);
val.AppendLiteral("The type ");
val.AppendFormatted<Type>(ImplementationType);
val.AppendLiteral(" does not implement the service type ");
val.AppendFormatted<Type>(ServiceType);
val.AppendLiteral(".");
error = val.ToStringAndClear();
return false;
}
internal bool ImplementationIsResolvable(out string error)
{
error = null;
if ((object)Context.Factory != null)
return true;
if (ImplementationType.IsResolvableType())
return true;
DefaultInterpolatedStringHandler val = default(DefaultInterpolatedStringHandler);
val..ctor(94, 1);
val.AppendLiteral("The type ");
val.AppendFormatted<Type>(ImplementationType);
val.AppendLiteral(" could not be resolved. It's probably an interface, abstract class or primitive type.");
error = val.ToStringAndClear();
return false;
}
}
}