Got an iPhone or iPad? We have a brand new Pastebin App for both devices, and it's totally free! Click here to download the new Pastebin App for iOS.
Guest

FuncContainer for IOC Battle benchmark

By: a guest on May 3rd, 2011  |  syntax: C#  |  size: 3.95 KB  |  hits: 136  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. using Funq;
  2. using IocBattle.Benchmark.Models;
  3.  
  4. namespace IocBattle.Benchmark.Tests
  5. {
  6.     public class FunqContainer : IContainer
  7.     {
  8.         private Container theContainer;
  9.  
  10.         public string Name
  11.         {
  12.             get { return "Funq"; }
  13.         }
  14.  
  15.         public T Resolve<T>() where T : class
  16.         {
  17.             return this.theContainer.Resolve<T>();
  18.         }
  19.  
  20.         public void SetupForTransientTest()
  21.         {
  22.             var container = new Container();
  23.  
  24.             container.Register<IRepository>(c => new Repository()).ReusedWithin(ReuseScope.None);
  25.             container.Register<IAuthenticationService>(c => new AuthenticationService()).ReusedWithin(ReuseScope.None);
  26.             container.Register<UserController>(c =>
  27.                 new UserController(c.Resolve<IRepository>(), c.Resolve<IAuthenticationService>())
  28.             ).ReusedWithin(ReuseScope.None);
  29.  
  30.             container.Register<IWebService>(c => new WebService(c.Resolve<IAuthenticator>(), c.Resolve<IStockQuote>())).ReusedWithin(ReuseScope.None);
  31.             container.Register<IAuthenticator>(c => new Authenticator(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>(), c.Resolve<IDatabase>())).ReusedWithin(ReuseScope.None);
  32.             container.Register<IStockQuote>(c => new StockQuote(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>(), c.Resolve<IDatabase>())).ReusedWithin(ReuseScope.None);
  33.             container.Register<IDatabase>(c => new Database(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>())).ReusedWithin(ReuseScope.None);
  34.             container.Register<IErrorHandler>(c => new ErrorHandler(c.Resolve<ILogger>())).ReusedWithin(ReuseScope.None);
  35.  
  36.             container.Register<IService1>(c => new Service1(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>())).ReusedWithin(ReuseScope.None);
  37.             container.Register<IService2>(c => new Service2(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>())).ReusedWithin(ReuseScope.None);
  38.             container.Register<IService3>(c => new Service3(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>())).ReusedWithin(ReuseScope.None);
  39.             container.Register<IService4>(c => new Service4(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>())).ReusedWithin(ReuseScope.None);
  40.  
  41.             container.Register<ILogger>(c => new Logger()).ReusedWithin(ReuseScope.None);
  42.  
  43.             this.theContainer = container;
  44.         }
  45.  
  46.         public void SetupForSingletonTest()
  47.         {
  48.             var container = new Container();
  49.  
  50.             container.Register<IRepository>(c => new Repository());
  51.             container.Register<IAuthenticationService>(c => new AuthenticationService());
  52.             container.Register<UserController>(c =>
  53.                 new UserController(c.Resolve<IRepository>(), c.Resolve<IAuthenticationService>())
  54.             );
  55.  
  56.             container.Register<IWebService>(c => new WebService(c.Resolve<IAuthenticator>(), c.Resolve<IStockQuote>()));
  57.             container.Register<IAuthenticator>(c => new Authenticator(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>(), c.Resolve<IDatabase>()));
  58.             container.Register<IStockQuote>(c => new StockQuote(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>(), c.Resolve<IDatabase>()));
  59.             container.Register<IDatabase>(c => new Database(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>()));
  60.             container.Register<IErrorHandler>(c => new ErrorHandler(c.Resolve<ILogger>()));
  61.  
  62.             container.Register<IService1>(c => new Service1(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>()));
  63.             container.Register<IService2>(c => new Service2(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>()));
  64.             container.Register<IService3>(c => new Service3(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>()));
  65.             container.Register<IService4>(c => new Service4(c.Resolve<ILogger>(), c.Resolve<IErrorHandler>()));
  66.  
  67.             container.Register<ILogger>(c => new Logger());
  68.  
  69.             this.theContainer = container;
  70.         }
  71.     }
  72. }