static async Task Main(string[] args) { Logger = new Logger(); ServiceLocator = new ServiceLocator(); Repository = new ParticipantRepository(Logger); Service = new ParticipantsService(Repository); MyMetod(); Logger = ServiceLocator.Resolve(typeof(ILogger)) as ILogger; Repository = ServiceLocator.Resolve(typeof(IParticipantRepository)) as IParticipantRepository; Service = ServiceLocator.Resolve(typeof(IParticipantsService)) as IParticipantsService; await Listen(); }
public static void HttpWebServer() { ServiceLocator.Register <IParticipantsRepository, ParticipantsRepository>(); ServiceLocator.Register <IParticipantsService, ParticipantsService>(); ServiceLocator.Register <ILogger, Logger>(); HttpListener listener = new HttpListener(); listener.Prefixes.Add("http://localhost:8881/"); listener.Start(); BaseController targetController; ParticipantsService service = (ParticipantsService)ServiceLocator.Resolve(typeof(IParticipantsService)); Logger logger = (Logger)ServiceLocator.Resolve(typeof(ILogger)); while (listener.IsListening) { HttpListenerContext context = listener.GetContext(); HttpListenerRequest request = context.Request; HttpListenerResponse response = context.Response; string requestPath = ROOT_PATH + request.Url.LocalPath; if (requestPath.Contains("participants")) { targetController = new ParticipantsController(service, logger); } else if (requestPath.Contains("vote")) { targetController = new VoteController(service, logger); } else { targetController = new IndexController(service, logger); } targetController.Handle(context); } }