Hi guys,
So i've read already about its not possible to make a abstract property static but then i'm a bit stuck and hoping you guys can show me a other way.
The setup:
It's a pretty simple setup actually, I believe most of you would use the naming repository but I use Service because my services does a bit more than just keep and get the objects.
What I basiclly want to accomplish it that I can register all my services that are derived from BaseService to have a SystemName so I can register them in the ServicesReposit ory. Now I just need one instance of the service and want to register it by a name. So I want to be able to do something along of:
UserService userService = ServicesReposit ory.Get(UserSer vice.SystemName );
So I think(!) I need a static abstact property because I want it to static(call with no instance, if I make a instance I defeat all purpose of this setup) but I want it in the BaseService or IBaseService so all the child classes must have systemName.
Any thoughts?
Many thanks,
Bryan
So i've read already about its not possible to make a abstract property static but then i'm a bit stuck and hoping you guys can show me a other way.
The setup:
Code:
_____________________ ___IBaseService public interface IBaseService<T> where T : BaseObject { T get(int id); BaseCollection<T> getAll(); bool add(T obj); bool remove(int id); bool remove(T obj); bool removeAll(BaseCollection<T> collection); } ___BaseService public abstract class BaseService { public abstract string SystemName { get; } public bool update() { try { return true; } catch (Exception exc) { return false; } } } ___ServicesRepository public class ServicesRepository { public static string SystemName = "ServicesRepository"; //The services private static Dictionary<string, BaseService> services; //Instance private static ServicesRepository instance; /// <summary> /// Get the instance of ServicesRepository /// </summary> public static ServicesRepository Instance { get { if (instance == null) instance = new ServicesRepository(); return instance; } } /// <summary> /// ServicesRepository: Centralization off the Services. /// </summary> public ServicesRepository() { if (services == null) this.registerServices(); } private void registerServices() { } public static BaseService Get(string systemName) { if (services.ContainsKey(systemName)) return services[systemName]; else return null; } }
What I basiclly want to accomplish it that I can register all my services that are derived from BaseService to have a SystemName so I can register them in the ServicesReposit ory. Now I just need one instance of the service and want to register it by a name. So I want to be able to do something along of:
UserService userService = ServicesReposit ory.Get(UserSer vice.SystemName );
So I think(!) I need a static abstact property because I want it to static(call with no instance, if I make a instance I defeat all purpose of this setup) but I want it in the BaseService or IBaseService so all the child classes must have systemName.
Any thoughts?
Many thanks,
Bryan
Comment