Home > General > Castle Windsor XML Angle Bracket Tax

Castle Windsor XML Angle Bracket Tax

Right. I mentioned in a really old post i would show you how to configure Windsor with XML. you need your code to look the the following and app.config to contain the following. Same senario as the last Windsor post but not compile safe. You pay the price if you make spelling mistakes or rename classes. No R# to help fix things up 🙂

using System.Net.Mail;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Castle.Windsor.Configuration.Interpreters;

namespace CastleWindsorDemos

    public interface IEmailSender
        void Send(MailMessage message);

    public class EmailSender : IEmailSender
        private readonly string server;
        private readonly int port;

        public EmailSender(string server, int port)
            this.server = server;
            this.port = port;

        public void Send(MailMessage message)
            //Provide detail later

    class Program
        static void Main(string[] args)
            WindsorContainer container = new WindsorContainer(new XmlInterpreter());
            IEmailSender sender = container.Resolve<IEmailSender>();

<?xml version="1.0" encoding="utf-8" ?>
        type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor" />
      <component id="emailservice" type="CastleWindsorDemos.EmailSender,CastleWindsorDemos"
                 service="CastleWindsorDemos.IEmailSender,CastleWindsorDemos" lifestyle="transient">
Categories: General Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: