C
C#3y ago
redfoxx

Global variables in .NET web application

What is a good way to define and use global variables in .NET web application? I have a simple e-commerce web app, and I have some variables that I want to use from inside any bounded context, all of which should be assigned a pre-defined value when building the app.
4 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
redfoxx
redfoxxOP3y ago
No, I did not. I read something about it but I don't really understand it. I can try.
Cracker
Cracker3y ago
If you want more than a global variable and some extra logic and more extendible workaround you can look at creating object instance as singleton lifetime, access through dependency injection https://learn.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-6.0 Its not direct definition of global variable but you can have little service that serves same instance of properties through injected singleton service (edit: as @Duke said static class with constants are what you are looking exactly)
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?