.NET Framework Web Application Hosting

We have recently been upgrading NServiceBus on an older legacy web application. We are moving from 2.x all the way to 7, so it has been challenging at times updating the endpoints. We have since begun working on our web projects inside of the solution and are a bit confused on how exactly we are supposed to set up NServiceBus on a web project for .NET Framework? We are on version 4.7.2 and cannot find any documentation surrounding .NET Framework and Web Applications. All of the documentation and samples are for .NETCORE. We know the older way is to have the following section added in the Application_Startup() in the Global.asax.cs file:

        NServiceBus.Configure.WithWeb()
            .Log4Net()
            .Autofac2Builder(this.Container)
                .XmlSerializer()
                .MsmqTransport()
                    .IsTransactional(true)
                    .PurgeOnStartup(false)
                .UnicastBus()
                    .ImpersonateSender(true)
                    .LoadMessageHandlers()
                .CreateBus()
                .Start();

I’ve been searching for something to help point us in the right direction on how we can host NServiceBus via Web Application hosting, but for a .NET Framework MVC application.

In current versions of NServiceBus there’s not much difference in hosting. You’re self-hosting the endpoint, it just happens to be inside an MVC application.

At the end you get an IEndpointInstance which fills the same role as your IBus in version 2.x. You can use dependency injection to inject that into your MVC controllers (or cast it to an IMessageSession so that a controller can’t stop the endpoint) if you want. Or you can just make the message session available as a static variable from your Global.asax. So you can continue to do it ih the Application_Startup() as you were before.

1 Like

I see, and that does seem to be the case! We did figure that it was similar to our other endpoints that we have running as console applications, but like you said this one just happens to be inside of the web application.

Thanks!