PageRenderTime 47ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/ThinkEmailFomatter/IoCModules/ContextModule.cs

https://bitbucket.org/nicdao/frg-think-emailformatter
C# | 50 lines | 45 code | 5 blank | 0 comment | 0 complexity | a903b714433d9e47b4ffe5a0ebc7301e MD5 | raw file
Possible License(s): BSD-3-Clause
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using Autofac;
  6. using ThinkEmailFormatter.Controllers;
  7. using ThinkEmailFormatter.Models;
  8. using System.Web.Configuration;
  9. using System.Configuration;
  10. using Microsoft.Practices.EnterpriseLibrary.Logging;
  11. using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
  12. namespace ThinkEmailFormatter.IoCModules
  13. {
  14. public class ContextModule : Module
  15. {
  16. protected override void Load(ContainerBuilder builder)
  17. {
  18. string emailContextHost = ConfigurationManager.AppSettings["SmtpServer"];
  19. string fromAddress = ConfigurationManager.AppSettings["SmtpServer.FromAddress"];
  20. string attachmentsRoot = ConfigurationManager.AppSettings["Attachments.Root.Url"];
  21. builder
  22. .Register(c => new HttpContextWrapper(System.Web.HttpContext.Current))
  23. .As<HttpContextBase>()
  24. .Named<HttpContextBase>("HttpContext");
  25. builder
  26. .Register(c => new ControllerAggregateService
  27. (
  28. c.ResolveNamed<HttpContextBase>("HttpContext"),
  29. c.ResolveNamed<IThinkHelper>("ThinkHelper"),
  30. new EmailContext()
  31. {
  32. AttachmentsRootUrl = attachmentsRoot,
  33. Host = emailContextHost,
  34. FromEmail = fromAddress
  35. },
  36. EnterpriseLibraryContainer.Current.GetInstance<LogWriter>()
  37. ))
  38. .As<IControllerAggregateService>();
  39. builder
  40. .Register(c => new TemplateController(c.Resolve<IControllerAggregateService>()));
  41. builder
  42. .Register(c => new AttachmentsController(c.Resolve<IControllerAggregateService>()));
  43. }
  44. }
  45. }