lundi 30 mai 2016

Issues in implementing Windsor Castle at app config level

I have written a dummy program that implements Windsor castle below.But my problem is that i want to write its components in my WEB CONFIG but i don't able to know where to write what..can any one helps me in correcting that

Please correct me writing is App.config level of behaviour i.e to make it configurable??? Dummy Programm:

namespace NnjectFramework
{

    class Program
    {
#region  windsor castle
        interface IFoo
        {
            void test();
            void test2();
        }
        public class Foo: IFoo
        {
            private readonly string _arg1;
            private readonly string _arg2;

            public Foo(string arg1, string arg2)
            {
                _arg1 = arg1;
                _arg2 = arg2;
            }


            public void test()
            {
                Console.WriteLine("Success method 1");
            }
            public void test2()
            {
                Console.WriteLine("Success method 2");
            }
        }
        class Bar
        {
            private Foo bar;

            public Bar(Foo bar)
            {
                this.bar = bar;
            }
        }
        static void Main(string[] args)
        {

            IWindsorContainer container = new WindsorContainer();
            container.Register(Component.For<IFoo>().ImplementedBy<Foo>().LifeStyle.Is(LifestyleType.Transient).Named("AFooNamedFoo"));

            IFoo foo = container.Resolve<Foo>("AFooNamedFoo", new { arg1 = "hello", arg2 = "world" });
            foo.test();
            foo.test2();
            Console.ReadKey();

        }

        #endregion
        }

} 

What i have tried in App.config:

<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
  <components>

    <component id="uniqueId"
    service="Acme.Crm.Services.INotificationService, Acme.Crm"
    type="Acme.Crm.Services.EmailNotificationService, Acme.Crm"
    inspectionBehavior="all|declaredonly|none"
    lifestyle="transient"
    customLifestyleType="type that implements ILifestyleManager"
    componentActivatorType="type that implements IComponentActivator"
    initialPoolSize="2" maxPoolSize="6"></component>
  </components></configuration>

Aucun commentaire:

Enregistrer un commentaire