I'm creating a Nuget Package for Asp.Net Core. I want to make it simple to configure. So I decided to give a fluent way approach to add my Nuget to the service collection in ConfigureServices() in Asp.Net Core.
This is what I'm planning to do:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(options => options....);
services.AddMyNugetPackageName();
}
Inside my AddMyNugetPackageName() method,
public static IServiceCollection AddMyNugetPackageName(this IServiceCollection services)
{
services
.AddMvc(options => options.ModelBinderProviders.Insert(0, new MyModelBinderProvider()))
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
return services;
}
So now if people start using my Nuget package, will the AddMvc() inside my AddMyNugetPackageName() replace the AddMvc() in their ConfigureServices()? Will this cause any trouble to the end users?
If this will replace the user's AddMvc() in their ConfigureServices() then what is the best approach or how to handle this?
services.TryAddSingleton<IHttpContextAccessor,HttpContextAccessor>();inside myAddMyNugetPackageName(). So how can this be implemented in a better way? This is what I thought instead of asking my end user to add these three items inConfigureServices()I thought it would be better if I give a fluent approach