2

What's the recommended place to initialize things like background tasks, resource preloading and other application logic on ASP.NET MVC6?

I know this could be called in a Startup class but what bothers me is that it has nothing to do with IApplicationBuilder or IServicesCollection, so it seems out of place.

Should I just add back a Global.asax and keep it on Application_Start?

Thanks.

1 Answer 1

1

Startup is definitely the place to do application startup logic. Put that sort of thing in the constructor. The Configure and ConfigureServices functions are simply special hooks that the environment looks for to wire up services and middleware. That does not mean that those hooks are the purpose of Startup, only that those are one type of thing that may get bootstrapped there.

I would also recommend taking a look at creating your own services and middleware when appropriate. You may be able to accomplish some of your objectives there. For instance, you may be able to create a singleton service that loads resources once, but can then be injected into any controller that needs to access those resources.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.