c# - Singleton class inheritance -


i have declared singleton class protected constructor , derived in other classes.so derived classes instance can singleton or not.

is there way keep derived classes singleton?

here listing of thread-safe singleton class use:

namespace helpers.designpatterns { public class singleton<t> t : class {     private static volatile t _instance;     private static object _syncroot = new object();      protected singleton()     {     }      private static t createinstance()     {         constructorinfo cinfo = typeof(t).getconstructor(             bindingflags.instance | bindingflags.nonpublic,             null,             new type[0],             new parametermodifier[0]);          return (t)cinfo.invoke(null);     }      /// <summary>     /// Точка входа синглтона     /// </summary>     public static t instance     {                 {             if (_instance == null)             {                 lock (_syncroot)                 {                     if (_instance == null)                         _instance = createinstance();                 }             }              return _instance;         }     }   } } 

it's extremly simple create derieved class:

class credentialsmanager : singleton<credentialsmanager>

but not solution have more 1 singleton class in project. have 4 in mine :)


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -