Switch to MVP pattern
This commit is contained in:
48
Eve-O-Preview/ApplicationBase/LightInjectContainer.cs
Normal file
48
Eve-O-Preview/ApplicationBase/LightInjectContainer.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using LightInject;
|
||||
|
||||
namespace EveOPreview
|
||||
{
|
||||
// Adapts LighInject to the generic IoC interface
|
||||
sealed class LightInjectContainer : IIocContainer
|
||||
{
|
||||
private readonly ServiceContainer _container;
|
||||
|
||||
public LightInjectContainer()
|
||||
{
|
||||
this._container = new ServiceContainer(ContainerOptions.Default);
|
||||
}
|
||||
|
||||
public bool IsRegistered<TService>()
|
||||
{
|
||||
return this._container.CanGetInstance(typeof(TService), "");
|
||||
}
|
||||
|
||||
public void Register<TService>()
|
||||
{
|
||||
this._container.Register<TService>();
|
||||
}
|
||||
|
||||
public void Register<TService, TImplementation>()
|
||||
where TImplementation : TService
|
||||
{
|
||||
this._container.Register<TService, TImplementation>();
|
||||
}
|
||||
|
||||
public void Register<TService, TArgument>(Expression<Func<TArgument, TService>> factory)
|
||||
{
|
||||
this._container.Register(f => factory);
|
||||
}
|
||||
|
||||
public void RegisterInstance<T>(T instance)
|
||||
{
|
||||
this._container.RegisterInstance(instance);
|
||||
}
|
||||
|
||||
public TService Resolve<TService>()
|
||||
{
|
||||
return this._container.GetInstance<TService>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user