In a CMS where multiply packages might provide owin startup attributes, is there a way to create multiply startups classes?
If not I will have to create a startup class where package creaters can register their owin startup class and the cms startup class will take care of running these. But then if someone in a package puts in a startup attribute, it might be that his got run and not the cms startup.
Are there any way I can tell that my startup is the most important so that will run over all others?
The OwinStartup attribute specifies the production startup class is run. Create another OWIN Startup class and name it TestStartup .
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web. config. To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.
You can have multiple startup classes in an application and instruct the runtime to choose one of those. Multiple Owinstartup attributes can be declared with different friendly names and pass in the friendly name of the corresponding Startup class to be used using the appSetting owin:AppStartup. Here is a detailed documentation on how to have multiple startup attributes.
I know this is old but I recently ran into this problem and here is how I solved it. I had a 3rd party library that used this OwinStartup method, but I also needed it to map SignalR routes. So I simply made a startup class that loops through all loaded assemblies and finds there startup classes and invokes them
[assembly: OwinStartupAttribute(typeof(TestWeb.Startup))]
namespace TestWeb
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
foreach (Assembly startupAssembly in System.AppDomain.CurrentDomain.GetAssemblies().Where(assembly => assembly.GetCustomAttribute<OwinStartupAttribute>() != null))
{
OwinStartupAttribute startupAttribute = startupAssembly.GetCustomAttribute<OwinStartupAttribute>();
if (startupAttribute.StartupType != typeof(TestWeb.Startup))
{
object startupClass = Activator.CreateInstance(startupAttribute.StartupType);
string startupMethod = string.IsNullOrEmpty(startupAttribute.MethodName) ? "Configuration" : startupAttribute.MethodName;
startupAttribute.StartupType.GetMethod(startupMethod).Invoke(startupClass, new object[] { app });
}
}
}
}
}
But if you don't need the IAppBuilder instance you could use the WebActivatorEx instead
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With