Dependency injection in ASP.NET

Out of the box, you get dependency injection in ASP.NET, and can inject items into a controller constructor, or a view, with a very simple configuration step. IConfiguration comes free, as does logging. And the framework provides others, like IHttpContextAccessor, which lets you easily access HTTP stuff outside of a controller or view.

You get scoped, transient, and singleton items, and automatic disposal for scoped items once a request is completed.

Learn more about dependency injection in the docs.

View code on GitHub

Comments

Popular posts from this blog

C# Record Serialization

Versioned content in MVC

Add timestamp to photo using ImageMagick