I have different services which each one has different types. For example UpdateService has three different types (HighFreq,MediumFreq,MinFreq).
I have made an enumaration for my services and my types for example:
public enum UpdateServiceType: byte
{
MinUpdateFreq= 1,
MediumUpdateFreq = 2,
HighUpdateFreq = 3
}
and
public enum MyServices: byte
{
UpdateService = 1,
SpecialService= 2,
}
Then on conditions on saved the service and associated type on database like :
serviceId= 1
ServiceType =2
Now I want to create each service but I don't know which pattern to use : factory pattern, service locator, or even I don't whether I have done the right thing to use enum or not?
what should i use instead of enum? How should i create the appropriate service? what are the best practices? How can I use an ioc like unity in this situation?
Update:
After Reading Great post by Mark Seeman I find Metadata Role Hint appropriate for my problem because it explicitly describes the class. But then again I came to another problem. the factory that mark suggested was something like this:
public class UpdatePackageFactory : UpdatePackageFactory
{
private readonly IEnumerable<IUpdatePackage> _candidates;
public UpdatePackageFactory(IEnumerable<IUpdatePackage> candidates)
{
_candidates = candidates;
}
public IUpdatePackage GetUpdatePackage(UpdateFreq UpdateFreq)
{
return (from c in this._candidates
let handledMethod = c.GetType().GetCustomAttribute<HandleUpdateFreqAttribute>()
where handledMethod != null && handledMethod.UpdateFreq == UpdateFreq
select c).SingleOrDefault();
}
}
it takes and enum like
public enum UpdateFreq : byte
{
MinUpdateFreq= 1,
MediumUpdateFreq = 2,
HighUpdateFreq = 3
}
But now I want to make another factory which makes the above factory the factory it self is dependent on an enum like
public enum ServiceFactory: byte
{
UpdateService= 1,
SpecialService = 2,
HighUpdateFreq = 3
}
Using the above mentioned method I can make another factory that builds factory but the problem is each factory receives its own enum How to make factories that accept different enums. for example the would be a method on my factory which takes two enums as argument the first one would always be myservices but the second argument would change proportional to which factory it is. one time it may be updateFreq ,another time specialType or .....
public IUpdatePackage GetUpdatePackage(MyServices myServices,UpdateFreq updateFreq )
{
}
Or making another example here Abstract Factory factories have enum
enum MANUFACTURERS
{
NOKIA,
SAMSUNG,
HTC,
}
but what if each factory then again has its own enum for example NokiFactory accept an enum with different items on it an Htc accept another enum with different naming an so on.
How should I write such factory?