using Funq;
using IocBattle.Benchmark.Models;
namespace IocBattle.Benchmark.Tests
{
public class FunqContainer : IContainer
{
private Container theContainer;
public string Name
{
get { return "Funq"; }
}
public T Resolve<T>() where T : class
{
return this.theContainer.Resolve<T>();
}
public void SetupForTransientTest()
{
var container = new Container();
container.Register<IRepository>(c => new Repository()).ReusedWithin(ReuseScope.None);
container.Register<IAuthenticationService>(c => new AuthenticationService()).ReusedWithin(ReuseScope.None);
container.Register<UserController>(c =>
new UserController(c.Resolve<IRepository>(), c.Resolve<IAuthenticationService>())
).ReusedWithin(ReuseScope.None);
container.Register<IWebService>(c => new WebService(c.Resolve<IAuthenticator>(), c.Resolve<IStockQuote>())).ReusedWithin(ReuseScope.None);
container.Register<IAuthenticator>(c => new Authenticator(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>(), c.Resolve<IDatabase>())).ReusedWithin(ReuseScope.None);
container.Register<IStockQuote>(c => new StockQuote(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>(), c.Resolve<IDatabase>())).ReusedWithin(ReuseScope.None);
container.Register<IDatabase>(c => new Database(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>())).ReusedWithin(ReuseScope.None);
container.Register<IErrorHandler>(c => new ErrorHandler(c.Resolve<ILogger>())).ReusedWithin(ReuseScope.None);
container.Register<IService1>(c => new Service1(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>())).ReusedWithin(ReuseScope.None);
container.Register<IService2>(c => new Service2(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>())).ReusedWithin(ReuseScope.None);
container.Register<IService3>(c => new Service3(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>())).ReusedWithin(ReuseScope.None);
container.Register<IService4>(c => new Service4(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>())).ReusedWithin(ReuseScope.None);
container.Register<ILogger>(c => new Logger()).ReusedWithin(ReuseScope.None);
this.theContainer = container;
}
public void SetupForSingletonTest()
{
var container = new Container();
container.Register<IRepository>(c => new Repository());
container.Register<IAuthenticationService>(c => new AuthenticationService());
container.Register<UserController>(c =>
new UserController(c.Resolve<IRepository>(), c.Resolve<IAuthenticationService>())
);
container.Register<IWebService>(c => new WebService(c.Resolve<IAuthenticator>(), c.Resolve<IStockQuote>()));
container.Register<IAuthenticator>(c => new Authenticator(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>(), c.Resolve<IDatabase>()));
container.Register<IStockQuote>(c => new StockQuote(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>(), c.Resolve<IDatabase>()));
container.Register<IDatabase>(c => new Database(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>()));
container.Register<IErrorHandler>(c => new ErrorHandler(c.Resolve<ILogger>()));
container.Register<IService1>(c => new Service1(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>()));
container.Register<IService2>(c => new Service2(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>()));
container.Register<IService3>(c => new Service3(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>()));
container.Register<IService4>(c => new Service4(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>()));
container.Register<ILogger>(c => new Logger());
this.theContainer = container;
}
}
}