1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| [ServiceContract]
[ServiceKnownType(typeof(Address))]
[ServiceKnownType(typeof(Article))]
[ServiceKnownType(typeof(Author))]
[ServiceKnownType(typeof(Blog))]
[ServiceKnownType(typeof(Category))]
[ServiceKnownType(typeof(News))]
[ServiceKnownType(typeof(Post))]
[ServiceKnownType(typeof(Ticket))]
[ServiceKnownType(typeof(Tip))]
public interface IPracticeService : IService<EntityObject>
{
}
public class PracticeService : Service<EntityObject>, IPracticeService
{
public PracticeService()
{
Managers = new ManagerFactory(typeof(PostManager));
}
}
public abstract class Service<T> : IService<T> where T : class, IEntityWithKey
{
protected virtual ManagerFactory Managers { get; set; }
public void Manage(T entity, ManageAction action)
{
object manager = Managers.Get(entity.GetType());
manager.GetType().GetMethod(Enum.GetName(typeof(ManageAction),action)).Invoke(manager, new object[] { entity });
}
public IEnumerable<T> List(Type type)
{
object manager = Managers.Get(type);
return (IEnumerable<T>)manager.GetType().GetMethod("List").Invoke(manager, new object[0]);
}
} |