Switch to MVP pattern

This commit is contained in:
Anton Kasyanov
2016-05-22 18:37:04 +03:00
parent 5e276b7a98
commit 362fd0b8d4
41 changed files with 2060 additions and 1265 deletions

View File

@@ -0,0 +1,69 @@
namespace EveOPreview
{
public class ApplicationController : IApplicationController
{
private readonly IIocContainer _container;
public ApplicationController(IIocContainer container)
{
this._container = container;
this._container.RegisterInstance<IApplicationController>(this);
}
public IApplicationController RegisterView<TView, TImplementation>()
where TView : IView
where TImplementation : class, TView
{
this._container.Register<TView, TImplementation>();
return this;
}
public IApplicationController RegisterInstance<TArgument>(TArgument instance)
{
this._container.RegisterInstance(instance);
return this;
}
public IApplicationController RegisterService<TService, TImplementation>()
where TImplementation : class, TService
{
this._container.Register<TService, TImplementation>();
return this;
}
public void Run<TPresenter>()
where TPresenter : class, IPresenter
{
if (!this._container.IsRegistered<TPresenter>())
{
this._container.Register<TPresenter>();
}
TPresenter presenter = this._container.Resolve<TPresenter>();
presenter.Run();
}
public void Run<TPresenter, TParameter>(TParameter args)
where TPresenter : class, IPresenter<TParameter>
{
if (!this._container.IsRegistered<TPresenter>())
{
this._container.Register<TPresenter>();
}
TPresenter presenter = this._container.Resolve<TPresenter>();
presenter.Run(args);
}
public TService Create<TService>()
where TService : class
{
if (!this._container.IsRegistered<TService>())
{
this._container.Register<TService>();
}
return this._container.Resolve<TService>();
}
}
}