Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Replace type in ServiceCollection for testing
public static class ServiceExtensions
public static ServiceCollection ReplaceWithFake<T>(this ServiceCollection services) where T : class
T fake = Substitute.For<T>();
var descriptor = new ServiceDescriptor(typeof(T), fake.GetType(), ServiceLifetime.Scoped);
return services;
// Usage: (install NSubstitute from Nuget)
// .ReplaceWithFake<IRepository>();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.