Mercurial > altnet-hispano
view Agendas/trunk/src/Agendas.Web/Global.asax.cs @ 128:1e47bf408073
Asignacion de los publicadores configurados en web.config al factory de agenda
(mediante CompositePublicador)
author | jorge.rowies |
---|---|
date | Mon, 04 Jul 2011 20:00:51 -0300 |
parents | db4b1e2cae49 |
children |
line wrap: on
line source
using System; using System.Collections.Generic; using System.Configuration; using System.Web.Mvc; using System.Web.Routing; using Agendas.Blog; using Agendas.Blog.Impl; using AltNetHispano.Agendas.Domain; using AltNetHispano.Agendas.Factories; using AltNetHispano.Agendas.Resources.Properties; using AltNetHispano.Agendas.Twitter; using AltNetHispano.Agendas.Web.CustomModelMetadataProvider; using Castle.MicroKernel.Registration; using Castle.Windsor; namespace AltNetHispano.Agendas.Web { // Note: For instructions on enabling IIS6 or IIS7 classic mode, // visit http://go.microsoft.com/?LinkId=9394801 public class MvcApplication : System.Web.HttpApplication { private static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); filters.Add(AttributeFactory.GetNHibernateSessionPerAction()); } private static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new {controller = "Home", action = "Index", id = UrlParameter.Optional} // Parameter defaults ); } private static readonly IWindsorContainer _container = new WindsorContainer(); protected void Application_Start() { InitContainer(); ModelMetadataProviders.Current = new DataAnnotationAndConventionModelMetadataProvider( new ResolverThroughResource<DataAnnotationResources>()); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); IdentityContext.Init(new HttpContextIdentityProvider(), AgendaFactory.GetPersonaRepository()); ConfigurarPublicadores(); } private static void InitContainer() { _container.Register( Component.For<IPublicador>().ImplementedBy<BlogPublicador>().Named("publicadores.blog").LifeStyle.Transient, Component.For<IPublicador>().ImplementedBy<TwitterPublicador>().Named("publicadores.twitter").LifeStyle.Transient, Component.For<IPostWriterFactory>().ImplementedBy<PostWriterFactory>().LifeStyle.Transient, Component.For<IPostWriterWebService>().ImplementedBy<PostWriterWebServiceAdapter>().LifeStyle.Transient, Component.For<BlogPublicadorConfig>().Instance( new BlogPublicadorConfig(ConfigurationManager.AppSettings["PublicadorBlog.PostWriterServiceUrl"], ConfigurationManager.AppSettings["PublicadorBlog.BlogName"], ConfigurationManager.AppSettings["PublicadorBlog.BlogWriterMasterKey"]) ).LifeStyle.Transient, Component.For<ITwitterAdapter>().ImplementedBy<TwitterAdapter>().LifeStyle.Transient ); } private static void ConfigurarPublicadores() { var cfg = (PublicadorConfigurationSection)ConfigurationManager.GetSection("publicadoresSection"); var publicadores = new List<IPublicador>(); foreach (PublicadorConfigurationElement pubCfg in cfg.Publicadores) { if (pubCfg.Enabled) { var publicador = _container.Resolve<IPublicador>(pubCfg.ComponentKey); publicadores.Add(publicador); } } AgendaFactory.Publicador = new CompositePublicador(publicadores); } } }