Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it not possible to have multiply OwinStartup attributes?

Tags:

owin

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?

like image 725
Poul K. Sørensen Avatar asked Sep 28 '13 12:09

Poul K. Sørensen


People also ask

What is OwinStartup attribute?

The OwinStartup attribute specifies the production startup class is run. Create another OWIN Startup class and name it TestStartup .

How do I disable OWIN startup in web config?

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.


2 Answers

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.

like image 135
Praburaj Avatar answered Oct 13 '22 00:10

Praburaj


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

like image 37
Thorgeir Avatar answered Oct 12 '22 23:10

Thorgeir