Skip to content

LightInject fallback service provider #390

Answered by egil
dady8889 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @dady8889

I do not know how LightInject works, but the fallback service provider is being called when the primary cannot resolve the request, i.e.:

public object? GetService(Type serviceType)
	=> GetServiceInternal(serviceType);

private object? GetServiceInternal(Type serviceType)
{
	if (serviceProvider is null)
		serviceProvider = serviceCollection.BuildServiceProvider();

	var result = serviceProvider.GetService(serviceType);

	if (result is null && fallbackServiceProvider is not null)
		result = fallbackServiceProvider.GetService(serviceType);

	return result;
}

So I am not sure why your code is not working. Please create a minimal reproduction of the issue, but it in a repo or zip…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@dady8889
Comment options

@egil
Comment options

egil May 9, 2021
Maintainer

@egil
Comment options

egil May 10, 2021
Maintainer

Answer selected by egil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants