I have a couple of entities which will pretty much never change (i.e. a list of Countries, Regions etc.) And it got me thinking... would a static repository make sense for these entities in addition to the normal repositories? I say in addition, because these entities will still interact with other entities, and I still want them under a single Unit of Work so they share the same context.
However, I'm sure there is a better way to go about it. I'm new to ASP.NET and the .NET Framework, but is there a way to define application wide data that will be used throughout the life of the program? Is that the best way to go about it?
Or is it better to just define a static class with collections of these entities and I can just grab these from there when I need it?
You can use various storing (State Management) techniques. Follow below options for more information.
From sound of it, the two entities you are trying to store will not be memory intensive, so Application cache will be best bet here.
Why not just use a caching mechanism? I've used memchache successfully in situations like this.
I think Nexus23's answer covers the majority of your options. But I find for some data like this (US States, Cities) sometimes its best to not maintain a list at all as its just something for you to deal with in the future. Usability wise as well having a list of 190+ countries (the UN and the US recognize different lists) is not ideal for a user to scroll through.
The user of the application most likely will know whats correct better than you anyway unless you plan on updating with the geopolitical changes of the world.
If you need this list for functions like address validation or geolocation its better to defer to a service that is meant for that instead of trying to reroll internally (Google Maps API, etc.).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With