SHARE
TWEET

IService

BorisKotlyar May 25th, 2020 (edited) 814 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public interface IPoolManager
  2.     {
  3.         T Create<T>(params object[] args);
  4.         object Create(Type concreteType, params object[] args);
  5.         T CreateComponent<T>(params object[] args) where T : Component;
  6.         Component CreateComponent(Type componentType, params object[] args);
  7.     }
  8.  
  9.     public interface IService
  10.     {
  11.         void Init();
  12.     }
  13.  
  14.     public interface IServiceFactory
  15.     {
  16.         T CreateService<T>(BaseService model) where T : IService;
  17.     }
  18.    
  19.     public abstract class BaseService : IService
  20.     {
  21.         public abstract void Init();
  22.     }
  23.  
  24.     public class ServiceFactory : IServiceFactory
  25.     {
  26.         private readonly IPoolManager _poolManager;
  27.        
  28.         public ServiceFactory(IPoolManager poolManager)
  29.         {
  30.             _poolManager = poolManager;
  31.         }
  32.        
  33.         public T CreateService<T>(BaseService model) where T : IService
  34.         {
  35.             var type = typeof(T);
  36.             return (T)_poolManager.Create(type, model);
  37.         }
  38.     }
  39.  
  40.     public interface IServiceCommand
  41.     {
  42.         event EventHandler OnDone;
  43.         void Run();
  44.     }
  45.    
  46.     public class ServiceCommand : BaseService, IServiceCommand
  47.     {
  48.         public override void Init()
  49.         {
  50.         }
  51.  
  52.         public event EventHandler OnDone;
  53.         public void Run()
  54.         {
  55.            
  56.         }
  57.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top