/ThinkEmailFomatter/IoCModules/ContextModule.cs
C# | 50 lines | 45 code | 5 blank | 0 comment | 0 complexity | a903b714433d9e47b4ffe5a0ebc7301e MD5 | raw file
Possible License(s): BSD-3-Clause
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using Autofac;
- using ThinkEmailFormatter.Controllers;
- using ThinkEmailFormatter.Models;
- using System.Web.Configuration;
- using System.Configuration;
- using Microsoft.Practices.EnterpriseLibrary.Logging;
- using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
- namespace ThinkEmailFormatter.IoCModules
- {
- public class ContextModule : Module
- {
- protected override void Load(ContainerBuilder builder)
- {
- string emailContextHost = ConfigurationManager.AppSettings["SmtpServer"];
- string fromAddress = ConfigurationManager.AppSettings["SmtpServer.FromAddress"];
- string attachmentsRoot = ConfigurationManager.AppSettings["Attachments.Root.Url"];
- builder
- .Register(c => new HttpContextWrapper(System.Web.HttpContext.Current))
- .As<HttpContextBase>()
- .Named<HttpContextBase>("HttpContext");
- builder
- .Register(c => new ControllerAggregateService
- (
- c.ResolveNamed<HttpContextBase>("HttpContext"),
- c.ResolveNamed<IThinkHelper>("ThinkHelper"),
- new EmailContext()
- {
- AttachmentsRootUrl = attachmentsRoot,
- Host = emailContextHost,
- FromEmail = fromAddress
- },
- EnterpriseLibraryContainer.Current.GetInstance<LogWriter>()
- ))
- .As<IControllerAggregateService>();
- builder
- .Register(c => new TemplateController(c.Resolve<IControllerAggregateService>()));
- builder
- .Register(c => new AttachmentsController(c.Resolve<IControllerAggregateService>()));
- }
- }
- }