I'm creating my own Nuget package and for it work properly I need some configuration that own user that installed my package will set.
I noticed that some packages are configured in Startup.cs
mostly in Configure
and ConfigureServices
methods.
An exaple is Swagger package:
In the image above, is configured the api docs name in a swagger configuration. I need something like that. In one of my classes inside my package, it will need information setted by the user in Startup file.
The methods you see in startup are simply extensions on IServiceCollection
(for services
in ConfigureServices
) or IApplicationBuilder
(for app
in Configure
). In other words, you'd simply create something like:
public static class IServiceCollectionExtensions
{
public static IServiceCollection ConfigureMyStuff(this IServiceCollection services, string someParam, string someOtherParam)
{
// do stuff
return services;
}
}
Then in Startup
, the user will be able to do:
services.ConfigureMyStuff("some value for param", "some value for other param");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.