Where to put Global List of object used in the Application C#?How do I convert an enum to a list in C#?Deserialize JSON into C# dynamic object?How to Sort a List<T> by a property in the objectAre there any reasons to use private properties in C#?How do I turn a C# object into a JSON string in .NET?C# Sorted List by Value with ObjectConfigure Ninject for 3 layers architecture in MVC 4Why not inherit from List<T>?How to use Ninject inside a c# class librarycould not find connection string in entityframework
Should my PhD thesis be submitted under my legal name?
Is there any reason not to eat food that's been dropped on the surface of the moon?
Will it be accepted, if there is no ''Main Character" stereotype?
How do I define a right arrow with bar in LaTeX?
Time travel short story where a man arrives in the late 19th century in a time machine and then sends the machine back into the past
Applicability of Single Responsibility Principle
How can I replace every global instance of "x[2]" with "x_2"
The plural of 'stomach"
Why did Kant, Hegel, and Adorno leave some words and phrases in the Greek alphabet?
I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?
Was Spock the First Vulcan in Starfleet?
Why Were Madagascar and New Zealand Discovered So Late?
What are the ramifications of creating a homebrew world without an Astral Plane?
Minimal reference content
HashMap containsKey() returns false although hashCode() and equals() are true
Hide Select Output from T-SQL
How can I get through very long and very dry, but also very useful technical documents when learning a new tool?
At which point does a character regain all their Hit Dice?
Personal Teleportation as a Weapon
MaTeX, font size, and PlotLegends
Implement the Thanos sorting algorithm
Is there a good way to store credentials outside of a password manager?
apt-get update is failing in debian
How can I use the arrow sign in my bash prompt?
Where to put Global List of object used in the Application C#?
How do I convert an enum to a list in C#?Deserialize JSON into C# dynamic object?How to Sort a List<T> by a property in the objectAre there any reasons to use private properties in C#?How do I turn a C# object into a JSON string in .NET?C# Sorted List by Value with ObjectConfigure Ninject for 3 layers architecture in MVC 4Why not inherit from List<T>?How to use Ninject inside a c# class librarycould not find connection string in entityframework
Where to put Global List of object used in the Application C#?
Let's say I got a list of category, which I want to be able to use any time, without having to retrieve these categories each time I need to use it.
What I will do is to retrieve the categories and store it to the List of category at startup. Then I will use this List of category, to update the items if there is changes to the items or access the items when I need to do operations on the time.
How can I do this?
My application is splitted up in a console layer, dataaccess layer and Logic layer. Where do I usually store this kind of List in order to be able to access it any time?
Right now I'm having a
public dynamic Categories get; set;
Which I save the data to.
I'm using dependency injection, Ninject.
c#
add a comment |
Where to put Global List of object used in the Application C#?
Let's say I got a list of category, which I want to be able to use any time, without having to retrieve these categories each time I need to use it.
What I will do is to retrieve the categories and store it to the List of category at startup. Then I will use this List of category, to update the items if there is changes to the items or access the items when I need to do operations on the time.
How can I do this?
My application is splitted up in a console layer, dataaccess layer and Logic layer. Where do I usually store this kind of List in order to be able to access it any time?
Right now I'm having a
public dynamic Categories get; set;
Which I save the data to.
I'm using dependency injection, Ninject.
c#
Be aware that the collection needs to be thread safe if updates to it are done after startups. (while reading might be happening)
– Magnus
Mar 8 at 9:38
Startup of what application? A desktop application or a single-server web application could just store the data in a static property. A web application though would need shared storage
– Panagiotis Kanavos
Mar 8 at 9:39
1
99.99% of the timedynamicpoints to a design problem
– Michael Randall
Mar 8 at 9:40
It's an console application for windows server. I'm going to change dynamic to the actual datatype.
– Bladeluster
Mar 8 at 9:44
add a comment |
Where to put Global List of object used in the Application C#?
Let's say I got a list of category, which I want to be able to use any time, without having to retrieve these categories each time I need to use it.
What I will do is to retrieve the categories and store it to the List of category at startup. Then I will use this List of category, to update the items if there is changes to the items or access the items when I need to do operations on the time.
How can I do this?
My application is splitted up in a console layer, dataaccess layer and Logic layer. Where do I usually store this kind of List in order to be able to access it any time?
Right now I'm having a
public dynamic Categories get; set;
Which I save the data to.
I'm using dependency injection, Ninject.
c#
Where to put Global List of object used in the Application C#?
Let's say I got a list of category, which I want to be able to use any time, without having to retrieve these categories each time I need to use it.
What I will do is to retrieve the categories and store it to the List of category at startup. Then I will use this List of category, to update the items if there is changes to the items or access the items when I need to do operations on the time.
How can I do this?
My application is splitted up in a console layer, dataaccess layer and Logic layer. Where do I usually store this kind of List in order to be able to access it any time?
Right now I'm having a
public dynamic Categories get; set;
Which I save the data to.
I'm using dependency injection, Ninject.
c#
c#
asked Mar 8 at 9:31
BladelusterBladeluster
195
195
Be aware that the collection needs to be thread safe if updates to it are done after startups. (while reading might be happening)
– Magnus
Mar 8 at 9:38
Startup of what application? A desktop application or a single-server web application could just store the data in a static property. A web application though would need shared storage
– Panagiotis Kanavos
Mar 8 at 9:39
1
99.99% of the timedynamicpoints to a design problem
– Michael Randall
Mar 8 at 9:40
It's an console application for windows server. I'm going to change dynamic to the actual datatype.
– Bladeluster
Mar 8 at 9:44
add a comment |
Be aware that the collection needs to be thread safe if updates to it are done after startups. (while reading might be happening)
– Magnus
Mar 8 at 9:38
Startup of what application? A desktop application or a single-server web application could just store the data in a static property. A web application though would need shared storage
– Panagiotis Kanavos
Mar 8 at 9:39
1
99.99% of the timedynamicpoints to a design problem
– Michael Randall
Mar 8 at 9:40
It's an console application for windows server. I'm going to change dynamic to the actual datatype.
– Bladeluster
Mar 8 at 9:44
Be aware that the collection needs to be thread safe if updates to it are done after startups. (while reading might be happening)
– Magnus
Mar 8 at 9:38
Be aware that the collection needs to be thread safe if updates to it are done after startups. (while reading might be happening)
– Magnus
Mar 8 at 9:38
Startup of what application? A desktop application or a single-server web application could just store the data in a static property. A web application though would need shared storage
– Panagiotis Kanavos
Mar 8 at 9:39
Startup of what application? A desktop application or a single-server web application could just store the data in a static property. A web application though would need shared storage
– Panagiotis Kanavos
Mar 8 at 9:39
1
1
99.99% of the time
dynamic points to a design problem– Michael Randall
Mar 8 at 9:40
99.99% of the time
dynamic points to a design problem– Michael Randall
Mar 8 at 9:40
It's an console application for windows server. I'm going to change dynamic to the actual datatype.
– Bladeluster
Mar 8 at 9:44
It's an console application for windows server. I'm going to change dynamic to the actual datatype.
– Bladeluster
Mar 8 at 9:44
add a comment |
2 Answers
2
active
oldest
votes
Please create as static.
public static dynamic Categories get; set;
CAn I just use public dynamic Categories get; set; ?
– Bladeluster
Mar 8 at 9:39
add a comment |
Not sure if you need DI for that, but one thing you could do is declare a static class lets say CategoriesCache which has a static list (or any kind of approporiate datastructure) and fetch the list at application startup. After that you can use that list. Maybe store it at app shutdown.
If you want to solve it with DI I can provide you with a snippet (SimpleInjector, but you can tailor it to your needs) for a similar problem:
public class ServiceBootstrapper
serviceContainer.Register<IApplicationSettings>(() => ApplicationSettings.Read(), Lifestyle.Singleton);
Note: This isn't a proper thing to do if your categories ever change during app lifecycle.
I'm using DI right now in the application. Do you mean that I should get the data and store it to a file, then for each time I need this data I have to retrieve it from the file?
– Bladeluster
Mar 8 at 9:42
No. What I mean is that you application should have a static class. For example Categories cache, which will have a static List<Categories> and when your bootstrapping completes you call a method (which you have to write) that uses the repository to retrieve data and initializes this static field on the static class once. This will be stored in the memory not in a file. Of course you should consider things like what will you do if the categories change in the meantime (e.g. multi-user environment) do you have to "invalidate the cache" and so on :)
– Kristóf Tóth
Mar 8 at 10:08
Could this be done without using static, but like dependency inject?
– Bladeluster
Mar 8 at 10:21
Well you could also do something like a custom factory which always returns a singleton instance of IEnumerable<Categories> but it's more complicated. github.com/ninject/Ninject/wiki/…
– Kristóf Tóth
Mar 8 at 10:30
could you provide an example? I'm using ninject for most of my interfaces throughout the host / console atm.
– Bladeluster
Mar 8 at 10:39
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060278%2fwhere-to-put-global-list-of-object-used-in-the-application-c%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Please create as static.
public static dynamic Categories get; set;
CAn I just use public dynamic Categories get; set; ?
– Bladeluster
Mar 8 at 9:39
add a comment |
Please create as static.
public static dynamic Categories get; set;
CAn I just use public dynamic Categories get; set; ?
– Bladeluster
Mar 8 at 9:39
add a comment |
Please create as static.
public static dynamic Categories get; set;
Please create as static.
public static dynamic Categories get; set;
answered Mar 8 at 9:34
Hemang AgheraHemang Aghera
5668
5668
CAn I just use public dynamic Categories get; set; ?
– Bladeluster
Mar 8 at 9:39
add a comment |
CAn I just use public dynamic Categories get; set; ?
– Bladeluster
Mar 8 at 9:39
CAn I just use public dynamic Categories get; set; ?
– Bladeluster
Mar 8 at 9:39
CAn I just use public dynamic Categories get; set; ?
– Bladeluster
Mar 8 at 9:39
add a comment |
Not sure if you need DI for that, but one thing you could do is declare a static class lets say CategoriesCache which has a static list (or any kind of approporiate datastructure) and fetch the list at application startup. After that you can use that list. Maybe store it at app shutdown.
If you want to solve it with DI I can provide you with a snippet (SimpleInjector, but you can tailor it to your needs) for a similar problem:
public class ServiceBootstrapper
serviceContainer.Register<IApplicationSettings>(() => ApplicationSettings.Read(), Lifestyle.Singleton);
Note: This isn't a proper thing to do if your categories ever change during app lifecycle.
I'm using DI right now in the application. Do you mean that I should get the data and store it to a file, then for each time I need this data I have to retrieve it from the file?
– Bladeluster
Mar 8 at 9:42
No. What I mean is that you application should have a static class. For example Categories cache, which will have a static List<Categories> and when your bootstrapping completes you call a method (which you have to write) that uses the repository to retrieve data and initializes this static field on the static class once. This will be stored in the memory not in a file. Of course you should consider things like what will you do if the categories change in the meantime (e.g. multi-user environment) do you have to "invalidate the cache" and so on :)
– Kristóf Tóth
Mar 8 at 10:08
Could this be done without using static, but like dependency inject?
– Bladeluster
Mar 8 at 10:21
Well you could also do something like a custom factory which always returns a singleton instance of IEnumerable<Categories> but it's more complicated. github.com/ninject/Ninject/wiki/…
– Kristóf Tóth
Mar 8 at 10:30
could you provide an example? I'm using ninject for most of my interfaces throughout the host / console atm.
– Bladeluster
Mar 8 at 10:39
add a comment |
Not sure if you need DI for that, but one thing you could do is declare a static class lets say CategoriesCache which has a static list (or any kind of approporiate datastructure) and fetch the list at application startup. After that you can use that list. Maybe store it at app shutdown.
If you want to solve it with DI I can provide you with a snippet (SimpleInjector, but you can tailor it to your needs) for a similar problem:
public class ServiceBootstrapper
serviceContainer.Register<IApplicationSettings>(() => ApplicationSettings.Read(), Lifestyle.Singleton);
Note: This isn't a proper thing to do if your categories ever change during app lifecycle.
I'm using DI right now in the application. Do you mean that I should get the data and store it to a file, then for each time I need this data I have to retrieve it from the file?
– Bladeluster
Mar 8 at 9:42
No. What I mean is that you application should have a static class. For example Categories cache, which will have a static List<Categories> and when your bootstrapping completes you call a method (which you have to write) that uses the repository to retrieve data and initializes this static field on the static class once. This will be stored in the memory not in a file. Of course you should consider things like what will you do if the categories change in the meantime (e.g. multi-user environment) do you have to "invalidate the cache" and so on :)
– Kristóf Tóth
Mar 8 at 10:08
Could this be done without using static, but like dependency inject?
– Bladeluster
Mar 8 at 10:21
Well you could also do something like a custom factory which always returns a singleton instance of IEnumerable<Categories> but it's more complicated. github.com/ninject/Ninject/wiki/…
– Kristóf Tóth
Mar 8 at 10:30
could you provide an example? I'm using ninject for most of my interfaces throughout the host / console atm.
– Bladeluster
Mar 8 at 10:39
add a comment |
Not sure if you need DI for that, but one thing you could do is declare a static class lets say CategoriesCache which has a static list (or any kind of approporiate datastructure) and fetch the list at application startup. After that you can use that list. Maybe store it at app shutdown.
If you want to solve it with DI I can provide you with a snippet (SimpleInjector, but you can tailor it to your needs) for a similar problem:
public class ServiceBootstrapper
serviceContainer.Register<IApplicationSettings>(() => ApplicationSettings.Read(), Lifestyle.Singleton);
Note: This isn't a proper thing to do if your categories ever change during app lifecycle.
Not sure if you need DI for that, but one thing you could do is declare a static class lets say CategoriesCache which has a static list (or any kind of approporiate datastructure) and fetch the list at application startup. After that you can use that list. Maybe store it at app shutdown.
If you want to solve it with DI I can provide you with a snippet (SimpleInjector, but you can tailor it to your needs) for a similar problem:
public class ServiceBootstrapper
serviceContainer.Register<IApplicationSettings>(() => ApplicationSettings.Read(), Lifestyle.Singleton);
Note: This isn't a proper thing to do if your categories ever change during app lifecycle.
edited Mar 8 at 10:35
answered Mar 8 at 9:35
Kristóf TóthKristóf Tóth
520314
520314
I'm using DI right now in the application. Do you mean that I should get the data and store it to a file, then for each time I need this data I have to retrieve it from the file?
– Bladeluster
Mar 8 at 9:42
No. What I mean is that you application should have a static class. For example Categories cache, which will have a static List<Categories> and when your bootstrapping completes you call a method (which you have to write) that uses the repository to retrieve data and initializes this static field on the static class once. This will be stored in the memory not in a file. Of course you should consider things like what will you do if the categories change in the meantime (e.g. multi-user environment) do you have to "invalidate the cache" and so on :)
– Kristóf Tóth
Mar 8 at 10:08
Could this be done without using static, but like dependency inject?
– Bladeluster
Mar 8 at 10:21
Well you could also do something like a custom factory which always returns a singleton instance of IEnumerable<Categories> but it's more complicated. github.com/ninject/Ninject/wiki/…
– Kristóf Tóth
Mar 8 at 10:30
could you provide an example? I'm using ninject for most of my interfaces throughout the host / console atm.
– Bladeluster
Mar 8 at 10:39
add a comment |
I'm using DI right now in the application. Do you mean that I should get the data and store it to a file, then for each time I need this data I have to retrieve it from the file?
– Bladeluster
Mar 8 at 9:42
No. What I mean is that you application should have a static class. For example Categories cache, which will have a static List<Categories> and when your bootstrapping completes you call a method (which you have to write) that uses the repository to retrieve data and initializes this static field on the static class once. This will be stored in the memory not in a file. Of course you should consider things like what will you do if the categories change in the meantime (e.g. multi-user environment) do you have to "invalidate the cache" and so on :)
– Kristóf Tóth
Mar 8 at 10:08
Could this be done without using static, but like dependency inject?
– Bladeluster
Mar 8 at 10:21
Well you could also do something like a custom factory which always returns a singleton instance of IEnumerable<Categories> but it's more complicated. github.com/ninject/Ninject/wiki/…
– Kristóf Tóth
Mar 8 at 10:30
could you provide an example? I'm using ninject for most of my interfaces throughout the host / console atm.
– Bladeluster
Mar 8 at 10:39
I'm using DI right now in the application. Do you mean that I should get the data and store it to a file, then for each time I need this data I have to retrieve it from the file?
– Bladeluster
Mar 8 at 9:42
I'm using DI right now in the application. Do you mean that I should get the data and store it to a file, then for each time I need this data I have to retrieve it from the file?
– Bladeluster
Mar 8 at 9:42
No. What I mean is that you application should have a static class. For example Categories cache, which will have a static List<Categories> and when your bootstrapping completes you call a method (which you have to write) that uses the repository to retrieve data and initializes this static field on the static class once. This will be stored in the memory not in a file. Of course you should consider things like what will you do if the categories change in the meantime (e.g. multi-user environment) do you have to "invalidate the cache" and so on :)
– Kristóf Tóth
Mar 8 at 10:08
No. What I mean is that you application should have a static class. For example Categories cache, which will have a static List<Categories> and when your bootstrapping completes you call a method (which you have to write) that uses the repository to retrieve data and initializes this static field on the static class once. This will be stored in the memory not in a file. Of course you should consider things like what will you do if the categories change in the meantime (e.g. multi-user environment) do you have to "invalidate the cache" and so on :)
– Kristóf Tóth
Mar 8 at 10:08
Could this be done without using static, but like dependency inject?
– Bladeluster
Mar 8 at 10:21
Could this be done without using static, but like dependency inject?
– Bladeluster
Mar 8 at 10:21
Well you could also do something like a custom factory which always returns a singleton instance of IEnumerable<Categories> but it's more complicated. github.com/ninject/Ninject/wiki/…
– Kristóf Tóth
Mar 8 at 10:30
Well you could also do something like a custom factory which always returns a singleton instance of IEnumerable<Categories> but it's more complicated. github.com/ninject/Ninject/wiki/…
– Kristóf Tóth
Mar 8 at 10:30
could you provide an example? I'm using ninject for most of my interfaces throughout the host / console atm.
– Bladeluster
Mar 8 at 10:39
could you provide an example? I'm using ninject for most of my interfaces throughout the host / console atm.
– Bladeluster
Mar 8 at 10:39
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060278%2fwhere-to-put-global-list-of-object-used-in-the-application-c%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Be aware that the collection needs to be thread safe if updates to it are done after startups. (while reading might be happening)
– Magnus
Mar 8 at 9:38
Startup of what application? A desktop application or a single-server web application could just store the data in a static property. A web application though would need shared storage
– Panagiotis Kanavos
Mar 8 at 9:39
1
99.99% of the time
dynamicpoints to a design problem– Michael Randall
Mar 8 at 9:40
It's an console application for windows server. I'm going to change dynamic to the actual datatype.
– Bladeluster
Mar 8 at 9:44