c# - How do I design a class that would normally be static when I'm using dependency injection? -
I have a class that acts as the default for app settings, which otherwise is not explicitly specified. Have been users
I am currently using an all-time old class, in which properly named example methods- this type of thing:
class SiteConfigurationConventions: ISiteConfigurationConventions { Public String GetConfigurationFileName) {return "SiteConfiguration.xml"; }}
It looks like a static
class would be more appropriately appropriate (such as System.Math
) because it is not a string Anytime changes in runtime and no fields are necessary, but I am not sure what static classes are compatible with D. For example, it is not possible to register a stable class with the container, Other objects to be resolved by the container Returns to ask Ts.
As it is now, / P>
container Registration Type & lt; ISite configuration, site configuration & gt; ();
The requestor constructor therefore requires:
public site generator (ISIT integration site configuration)
My Design options appear to be:
- Rather than using reflectors and constructor injections for a stable class, Concrete type refers directly to my consumer category
- Skip (class and example solution for an interface) Alternatively, to correct it, registration using Singleton Lifespan
- To hide any type of mask or factory stationary, however, for some reasons this option kills me silly.
An "example" of such a class seems weird-stagnant and seems more realistic. The only reason is that I want to make it an immediate class so that it is more favorable. Is this sound ok, or right? Am I completely missing something?
Any advice would be most appreciated :)
Most of the DI library Gives the option of specifying that an example can be used for all exigencies (creates an example and responds to it every time) It is a form of singleton, and possibly will suit your problem properly.
For example, using the MS Unity Library, you will enter:
Container. Registrar (new site configuration ()) ;;
I understand that the static
keyword is created as a singleton implementation, while the DI path works very similarly, but the use of the compiler Keep in mind the description without doing.
Comments
Post a Comment