public void Default_component_for_given_service_comes_first()
        {
            Container.Register(Component.For <IEmptyService, EmptyServiceA>().ImplementedBy <EmptyServiceA>(),
                               Component.For <IEmptyService>().ImplementedBy <EmptyServiceB>().IsDefault(),
                               Component.For <IEmptyService>().ImplementedBy <EmptyServiceDecorator>(),
                               Component.For <A>());

            var services = diagnostic.Inspect();

            Assert.AreEqual(typeof(EmptyServiceB), services[typeof(IEmptyService)].First().ComponentModel.Implementation);
        }
예제 #2
0
        public override IEnumerable <DebuggerViewItem> Attach()
        {
            var map   = diagnostic.Inspect();
            var items = map.OrderBy(p => p.Key.Name).Select(p => BuildServiceView(p, p.Key.Name)).ToArray();

            return(new[]
            {
                new DebuggerViewItem(name, "Count = " + items.Length, items)
            });
        }
예제 #3
0
파일: AllServices.cs 프로젝트: vtml/Windsor
        public override IEnumerable <DebuggerViewItem> Attach()
        {
            var map   = diagnostic.Inspect();
            var items = map.Select(p => BuildServiceView(p, p.Key.ToCSharpString())).ToArray();

            Array.Sort(items, (i1, i2) => i1.Name.CompareTo(i2.Name));
            return(new[]
            {
                new DebuggerViewItem(name, "Count = " + items.Length, items)
            });
        }
예제 #4
0
        static void Main(string[] args)
        {
#if true1
            WindsorContainer container = new WindsorContainer(new XmlInterpreter());
#else
            WindsorContainer container = new WindsorContainer();

            var depend = new Dictionary <string, object>()
            {
                { "rate", 0.23m },
                { "holidays", new DateTime[] { new DateTime(2014, 06, 06, 16, 09, 01), new DateTime(2014, 06, 06, 17, 09, 01), new DateTime(2014, 06, 06, 18, 09, 01) } },
                { "aliases", new Dictionary <string, string>()
                  {
                      { "aaa", "A1" }, { "bbb", "A2" }, { "ccc", "A3" }
                  } }
            };
            container.Register(Component.For <TaxCalculator>().DependsOn(depend));

            container.Register(Component.For <RMSInterceptor>().Named("RMSInterceptor.Service"));

            container.Register(Component.For <IRMS>().ImplementedBy <SimpleRMS>().Named("SimpleRMS.Service").Interceptors("RMSInterceptor.Service") /*.LifeStyle.PerWebRequest*/);
            container.Register(Component.For <IRMS>().ImplementedBy <SecondRMS>().Named("SecondRMS.Service").Interceptors("RMSInterceptor.Service") /*.LifeStyle.PerWebRequest*/);
#endif
            TaxCalculator calculator = container.Resolve <TaxCalculator>();

            decimal gross = 100;
            decimal tax   = calculator.CalculateTax(gross);
            Console.WriteLine("Gross: {0}, Tax: {1}", gross, tax);

            if (calculator.Holidays != null)
            {
                Console.WriteLine("数组:");
                foreach (var item in calculator.Holidays)
                {
                    Console.WriteLine(item.ToString("yyyy-MM-dd HH:mm:ss"));
                }
            }
            if (calculator.Aliases != null)
            {
                Console.WriteLine("字典:");
                foreach (var item in calculator.Aliases)
                {
                    Console.WriteLine("{0} : {1}", item.Key, item.Value);
                }
            }

            IRMS rms = container.Resolve <IRMS>("SecondRMS.Service");
            Console.WriteLine(rms.GetRole("ceshi"));

            //容器跟踪
            var host = (IDiagnosticsHost)container.Kernel.GetSubSystem(SubSystemConstants.DiagnosticsKey);
            IAllServicesDiagnostic diagnostic = host.GetDiagnostic <IAllServicesDiagnostic>();

            foreach (var item in diagnostic.Inspect())
            {
                Console.WriteLine(item.Key.ToString());

                foreach (var s in item)
                {
                    Console.WriteLine("\t{0},{1}", s.ToString(), s.CurrentState);
                }
            }
            ;

            Console.ReadKey();
        }