I am developing a helper library for EF Core and currently it works by providing a custom DbContext class but I want to add a way to use it without a custom base class. I can achieve it by inheriting from StateManager and telling EF to use my implementation for IStateManager.
I found two options for telling EF to use my implementation:
The first one is simply calling DbContextOptionsBuilder.ReplaceService Method.
Second way is to cast DbContextOptionsBuilder to IDbContextOptionsBuilderInfrastructure, call AddOrUpdateExtension on it, pass an IDbContextOptionsExtension instance and in ApplyServices method call ServiceCollectionServiceExtensions.AddScoped method.
Out of these two options which one is a preferred ? Is there any difference between these two approaches?