Hw to pass arguments to my own Startup class?
c#, owin
Solution
If you want to pass parameter to StartUp class, you can use `Action<IAppBuilder>` in WebApp.Start like Cillié Malan mentioned in the comment instead of launching with Type parameter(`WebApp.Start<T>`)
Here is a concrete example for self-hosting:
object someThingYouWantToAccess;
var server = WebApp.Start("http://localhost:8080/", (appBuilder) =>
{
// You can access someThingYouWantToAccess here
// Configure Web API for self-host.
HttpConfiguration config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
appBuilder.UseWebApi(config);
});
Problem
I'm trying to develop a web api self hosting app using OWIN. In my own XyzStartup class, I need an external argument: contentFolderPath. However, I didn't find a way to pass this argument. Here is my code below: ``` var contentFolderPath = this.TextBox.Text; // user input var startOptions = new StartOptions(); using(WebApp.Start<XyzStartup>(startOptions)){ } ``` My startup ``` public class XyzStartup { XyzStartup(string contentFolderPath) { ... } } ``` I noticed there is a StartOption class, but don't how to use it. Can I use it in my XyzStartup class? Thanks in advance! I finally find a way to do this: ``` var startOptions = new StartOptions(); startOptions.Urls.Add('..some url ..'); WebApp.Start(startOptions, (appBuilder)=>{ new XyzStartup(contentFolderPath).Configuration(appBuilder); } ```