Exemplo n.º 1
0
 public override void Init(IKernel kernel, IDiagnosticsHost diagnosticsHost)
 {
     diagnostic = new AllServicesDiagnostic(kernel);
     diagnosticsHost.AddDiagnostic(diagnostic);
 }
Exemplo n.º 2
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();
        }
		protected override void AfterContainerCreated()
		{
			var host = (IDiagnosticsHost)Kernel.GetSubSystem(SubSystemConstants.DiagnosticsKey);
			diagnostic = host.GetDiagnostic<IAllServicesDiagnostic>();
		}
Exemplo n.º 4
0
		public override void Init(IKernel kernel, IDiagnosticsHost diagnosticsHost)
		{
			diagnostic = new AllServicesDiagnostic(kernel);
			diagnosticsHost.AddDiagnostic(diagnostic);
		}
        protected override void AfterContainerCreated()
        {
            var host = (IDiagnosticsHost)Kernel.GetSubSystem(SubSystemConstants.DiagnosticsKey);

            diagnostic = host.GetDiagnostic <IAllServicesDiagnostic>();
        }