changeset 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 3700b77ed455
children
files Agendas/trunk/src/Agendas.Blog/Impl/BlogPublicador.cs Agendas/trunk/src/Agendas.Domain/Agenda.cs Agendas/trunk/src/Agendas.Factories/AgendaFactory.cs Agendas/trunk/src/Agendas.Tests/App.config Agendas/trunk/src/Agendas.Tests/PublicadoresConfigTests.cs Agendas/trunk/src/Agendas.Web/Agendas.Web.csproj Agendas/trunk/src/Agendas.Web/Global.asax.cs Agendas/trunk/src/Agendas.Web/PublicadoresConfig.cs Agendas/trunk/src/Agendas.Web/Web.config Agendas/trunk/src/Agendas.Web/packages.config
diffstat 10 files changed, 109 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Blog/Impl/BlogPublicador.cs	Sat Jul 02 21:50:05 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Blog/Impl/BlogPublicador.cs	Mon Jul 04 20:00:51 2011 -0300
@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Configuration;
 using System.Linq;
 using AltNetHispano.Agendas.Domain;
 
--- a/Agendas/trunk/src/Agendas.Domain/Agenda.cs	Sat Jul 02 21:50:05 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/Agenda.cs	Mon Jul 04 20:00:51 2011 -0300
@@ -12,7 +12,7 @@
 		private readonly IPublicador _publicador;
 
 		public Agenda(IPublicador publicador, IEventoRepository eventosRepository,
-		              IPersonaRepository personaRepository)
+									IPersonaRepository personaRepository)
 		{
 			_publicador = publicador;
 			_personaRepository = personaRepository;
@@ -71,7 +71,7 @@
 		public Resultado Proponer(string titulo, string ponenteNombre, string urlInvitacion, TipoEvento tipo)
 		{
 			Persona persona = GetPonente(ponenteNombre);
-      var evento = Evento.Proponer(titulo, persona, urlInvitacion, tipo);
+			var evento = Evento.Proponer(titulo, persona, urlInvitacion, tipo);
 
 			if (string.IsNullOrWhiteSpace(evento.Titulo))
 				return new Resultado(false);
@@ -84,7 +84,7 @@
 			return new Resultado(true);
 		}
 
-    public Resultado Agendar(string titulo, string ponenteNombre, DateTime? fecha, string urlInvitacion, TipoEvento tipo)
+		public Resultado Agendar(string titulo, string ponenteNombre, DateTime? fecha, string urlInvitacion, TipoEvento tipo)
 		{
 			if (!fecha.HasValue)
 				return new Resultado(false);
--- a/Agendas/trunk/src/Agendas.Factories/AgendaFactory.cs	Sat Jul 02 21:50:05 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Factories/AgendaFactory.cs	Mon Jul 04 20:00:51 2011 -0300
@@ -1,4 +1,5 @@
-using Agendas.NHibernate;
+using System.Collections.Generic;
+using Agendas.NHibernate;
 using AltNetHispano.Agendas.Domain;
 using AltNetHispano.Agendas.Domain.Repositories;
 using AltNetHispano.Agendas.Domain.Services;
@@ -11,6 +12,8 @@
 {
 	public static class AgendaFactory
 	{
+		public static IPublicador Publicador { get; set; }
+
 		private static Agenda _agenda;
 
 		public static Agenda GetAgenda()
@@ -18,7 +21,7 @@
 			ISessionFactory sessionFactory = NhHelper.GetSessionFactory();
 			return _agenda ??
 			       (_agenda =
-			        new Agenda(new TwitterPublicador(), new EventoRepository(sessionFactory),
+			        new Agenda(Publicador, new EventoRepository(sessionFactory),
 			                   new PersonaRepository(sessionFactory)));
 		}
 
--- a/Agendas/trunk/src/Agendas.Tests/App.config	Sat Jul 02 21:50:05 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Tests/App.config	Mon Jul 04 20:00:51 2011 -0300
@@ -11,8 +11,8 @@
 
 	<publicadoresSection>
 		<publicadores>
-			<add name="Blog" type="Agendas.Blog.Impl.BlogPublicador, Agendas.Blog" enabled="false"/>
-			<add name="Twitter" type="AltNetHispano.Agendas.Twitter.TwitterPublicador, AltNetHispano.Agendas.Twitter" enabled="true"/>
+			<add name="Blog" componentKey="publicador.blog" enabled="false"/>
+			<add name="Twitter" componentKey="publicador.twitter" enabled="true"/>
 		</publicadores>
 	</publicadoresSection>
 
--- a/Agendas/trunk/src/Agendas.Tests/PublicadoresConfigTests.cs	Sat Jul 02 21:50:05 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Tests/PublicadoresConfigTests.cs	Mon Jul 04 20:00:51 2011 -0300
@@ -18,9 +18,9 @@
 
 			Assert.IsNotNull(cfg);
 			Assert.AreEqual(2, cfg.Publicadores.Count);
-			Assert.AreEqual("Agendas.Blog.Impl.BlogPublicador", cfg.Publicadores["Blog"].GetPublicadorType().FullName);
+			Assert.AreEqual("publicador.blog", cfg.Publicadores["Blog"].ComponentKey);
 			Assert.AreEqual(false, cfg.Publicadores["Blog"].Enabled);
-			Assert.AreEqual("AltNetHispano.Agendas.Twitter.TwitterPublicador", cfg.Publicadores["Twitter"].GetPublicadorType().FullName);
+			Assert.AreEqual("publicador.twitter", cfg.Publicadores["Twitter"].ComponentKey);
 			Assert.AreEqual(true, cfg.Publicadores["Twitter"].Enabled);
 		}
 	}
--- a/Agendas/trunk/src/Agendas.Web/Agendas.Web.csproj	Sat Jul 02 21:50:05 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Web/Agendas.Web.csproj	Mon Jul 04 20:00:51 2011 -0300
@@ -34,6 +34,12 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="Castle.Core, Version=2.5.1.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
+      <HintPath>..\packages\Castle.Core.2.5.2\lib\NET35\Castle.Core.dll</HintPath>
+    </Reference>
+    <Reference Include="Castle.Windsor">
+      <HintPath>..\packages\Castle.Windsor.2.5.3\lib\NET40\Castle.Windsor.dll</HintPath>
+    </Reference>
     <Reference Include="DataAnnotationsExtensions">
       <HintPath>..\packages\DataAnnotationsExtensions.0.6.0.0\lib\NETFramework40\DataAnnotationsExtensions.dll</HintPath>
     </Reference>
--- a/Agendas/trunk/src/Agendas.Web/Global.asax.cs	Sat Jul 02 21:50:05 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Web/Global.asax.cs	Mon Jul 04 20:00:51 2011 -0300
@@ -1,47 +1,94 @@
-using System.Web.Mvc;
+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
+		// 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}");
 
-    public class MvcApplication : System.Web.HttpApplication
-    {
-    	private static void RegisterGlobalFilters(GlobalFilterCollection filters)
-        {
-            filters.Add(new HandleErrorAttribute());
-			filters.Add(AttributeFactory.GetNHibernateSessionPerAction());
-        }
+				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();
 
-    	private static void RegisterRoutes(RouteCollection routes)
-        {
-            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
+			protected void Application_Start()
+			{
+				InitContainer();
+
+				ModelMetadataProviders.Current =
+					new DataAnnotationAndConventionModelMetadataProvider(
+						new ResolverThroughResource<DataAnnotationResources>());
+
+				AreaRegistration.RegisterAllAreas();
+
+				RegisterGlobalFilters(GlobalFilters.Filters);
+				RegisterRoutes(RouteTable.Routes);
 
-            routes.MapRoute(
-                "Default", // Route name
-                "{controller}/{action}/{id}", // URL with parameters
-                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
-            );
+				IdentityContext.Init(new HttpContextIdentityProvider(), AgendaFactory.GetPersonaRepository());
 
-        }
+				ConfigurarPublicadores();
+			}
 
-        protected void Application_Start()
-        {
-        	ModelMetadataProviders.Current =
-        		new DataAnnotationAndConventionModelMetadataProvider(
-        			new ResolverThroughResource<DataAnnotationResources>());
-
-            AreaRegistration.RegisterAllAreas();
+			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
+					);
+			}
 
-            RegisterGlobalFilters(GlobalFilters.Filters);
-            RegisterRoutes(RouteTable.Routes);
+			private static void ConfigurarPublicadores()
+			{
+				var cfg = (PublicadorConfigurationSection)ConfigurationManager.GetSection("publicadoresSection");
 
-            IdentityContext.Init(new HttpContextIdentityProvider(), AgendaFactory.GetPersonaRepository());
-        }
-    }
+				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);
+			}
+		}
 }
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Web/PublicadoresConfig.cs	Sat Jul 02 21:50:05 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Web/PublicadoresConfig.cs	Mon Jul 04 20:00:51 2011 -0300
@@ -15,20 +15,15 @@
 			get { return (string)this["name"]; }
 		}
 
-		[ConfigurationProperty("type", IsRequired = true)]
-		public string Type
+		[ConfigurationProperty("componentKey", IsRequired = true)]
+		public string ComponentKey
 		{
 			get
 			{
-				return (string)this["type"];
+				return (string)this["componentKey"];
 			}
 		}
 
-		public Type GetPublicadorType()
-		{
-			return System.Type.GetType((string) this["type"]);
-		}
-
 		[ConfigurationProperty("enabled", IsRequired = true)]
 		public bool Enabled
 		{
--- a/Agendas/trunk/src/Agendas.Web/Web.config	Sat Jul 02 21:50:05 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Web/Web.config	Mon Jul 04 20:00:51 2011 -0300
@@ -25,6 +25,11 @@
 
 		<add key="ClientValidationEnabled" value="true"/>
 		<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
+
+		<add key="PublicadorBlog.PostWriterServiceUrl" value="http://localhost/TestAltNet/PostWriterWebService.asmx"/>
+		<add key="PublicadorBlog.BlogName" value="TestBlog"/>
+		<add key="PublicadorBlog.BlogWriterMasterKey" value="***"/>
+
 	</appSettings>
 
 	<system.web>
@@ -97,8 +102,8 @@
 
 	<publicadoresSection>
 		<publicadores>
-			<add name="Blog" type="Agendas.Blog.Impl.BlogPublicador, Agendas.Blog" enabled="false"/>
-			<add name="Twitter" type="AltNetHispano.Agendas.Twitter.TwitterPublicador, AltNetHispano.Agendas.Twitter" enabled="false"/>
+			<add name="Blog" componentKey="publicadores.blog" enabled="false"/>
+			<add name="Twitter" componentKey="publicadores.twitter" enabled="false"/>
 		</publicadores>
 	</publicadoresSection>
 
--- a/Agendas/trunk/src/Agendas.Web/packages.config	Sat Jul 02 21:50:05 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Web/packages.config	Mon Jul 04 20:00:51 2011 -0300
@@ -1,4 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
   <package id="DataAnnotationsExtensions" version="0.6.0.0" />
+  <package id="Castle.Core" version="2.5.2" />
+  <package id="Castle.Windsor" version="2.5.3" />
 </packages>
\ No newline at end of file