Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Skip method to UnknownRegistrationConfigurator #106

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Registration/Fluent/RegistrationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ internal RegistrationConfiguration(Type serviceType, Type implementationType, Re
internal bool TypeMapIsValid(out string error)
{
error = null;
if (this.ImplementationType == null)
{
error = $"Implementation type not set.";
return false;
}

if (this.Context.Factory != null)
return true;


if (!this.ImplementationType.IsResolvableType())
{
error = $"The type {this.ImplementationType} could not be resolved. It's probably an interface, abstract class or primitive type.";
Expand Down
14 changes: 14 additions & 0 deletions src/Registration/Fluent/UnknownRegistrationConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,19 @@ public UnknownRegistrationConfigurator SetImplementationType(Type implementation
return this;

}

/// <summary>
/// Resets the current registration's implementation type and factory settings and skips the registration.
/// </summary>
/// <returns>The configurator itself.</returns>
public UnknownRegistrationConfigurator Skip()
{
base.ImplementationType = null;
this.Context.Factory = null;
this.Context.FactoryParameters = null;
this.Context.IsFactoryDelegateACompiledLambda = false;

return this;
}
}
}
2 changes: 1 addition & 1 deletion src/Resolution/Resolvers/UnknownTypeResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Expression GetExpression(
var registrationConfigurator = new UnknownRegistrationConfigurator(typeInfo.Type, typeInfo.Type);
configurator?.Invoke(registrationConfigurator);

if (!registrationConfigurator.TypeMapIsValid(out _))
if (!registrationConfigurator.TypeMapIsValid(out _) && resolutionContext.GetDependencyOverrideOrDefault(typeInfo.Type) == null)
return null;

var registration = this.registrationBuilder.BuildServiceRegistration(resolutionContext.RequestInitiatorContainerContext,
Expand Down