JonPSmith / SampleMvcWebApp

A Sample MVC5 web application showing the use of GenericServices for CRUD operations
MIT License
74 stars 121 forks source link

Registering services as Singleton #5

Closed tej-rana closed 6 years ago

tej-rana commented 6 years ago

How do you register services as singleton or transient scoped? I have the need to load certain dto as singleton so every controller simply gets the same values. I thought about using a base controller but base controller loading data just does not seem like the way to go if there are many dtos I want to load - thereby injecting a lot of services which may or may not be needed.

JonPSmith commented 6 years ago

Hi @tesnep,

Not sure this is the best place to ask this. The answer will depend on what sort of dependency injection package you are using. All of them allow you to register something as a singleton. In this project (which is pretty old now) I use AutoFac - here is a link to registering a singleton.