Ejemplo n.º 1
0
        public static void Run()
        {
            var container = new Castle.Windsor.WindsorContainer();

            container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel));

            container.Register(
                Component
                .For <ServiceBase>()
                .ImplementedBy <ServiceA>()
                .LifestyleTransient(),
                Component
                .For <ServiceBase>()
                .ImplementedBy <ServiceB>()
                .LifestyleTransient(),
                Component
                .For <IWantAllServicessService>()
                .ImplementedBy <IWantAllServicessService>()
                .LifestyleTransient()
                );

            var service = container.Resolve <ServiceBase>();
            // to na później
            var iWantAll = container.Resolve <IWantAllServicessService>();

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        public void Config()
        {
            var c        = new Castle.Windsor.WindsorContainer();
            var endpoint = CodeSharp.ServiceFramework.Configuration
                           .Configure()
                           .Castle(c)
                           .Log4Net(true)
                           .Associate(new Uri(System.Configuration.ConfigurationManager.AppSettings["CenterUri"]))
                           .Identity(new CodeSharp.ServiceFramework.Identity()
            {
                Source = "NTFE-BPM", AuthKey = "75DC6B572D1B940E34159DCD7FF26D8D"
            })
                           .Endpoint();

            endpoint.Run();

            this._log           = endpoint.Resolve <ILoggerFactory>().Create(this.GetType());
            this._clientApi     = c.Resolve <Taobao.Workflow.Activities.Client.ITFlowEngine>();
            this._managementApi = c.Resolve <Taobao.Workflow.Activities.Management.ITFlowEngine>();

            //NTFE使用ID作为账号库用户名
            //UDONE:由于人员服务未做mock,因此目前取固定值
            this._originator = "5FE9A969-7CB2-4BA7-9601-E11473E8B233"; //this.GetMappedUserId(this._originator).ToString();
            this._superior   = "9D23EAA9-6145-4635-A7C2-D8AEEDF45C1E"; //this.GetMappedUserId(this._superior).ToString();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 解析一个服务
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static T Resolve <T>(string key = "")
 {
     if (string.IsNullOrEmpty(key))
     {
         return(Container.Resolve <T>());
     }
     else
     {
         return(Container.Resolve <T>(key));
     }
 }
Ejemplo n.º 4
0
        public void CanRestoreFormDynamicSnapshot()
        {
            //  We assert in each step!!!

            var target       = Assembly.LoadFrom("Ncqrs.Eventing.Sourcing.Snapshotting.DynamicSnapshot.Tests.dll");
            var snapshotsAsm = DynamicSnapshot.CreateAssemblyFrom(target);

            Castle.Windsor.IWindsorContainer container = new Castle.Windsor.WindsorContainer();
            container.Register(Component.For <Foo>().AsSnapshotable());

            dynamic proxy = container.Resolve <Foo>();

            proxy.ChangeTitle(OriginalTitle);
            Assert.AreEqual(OriginalTitle, proxy.Tittle);

            var snapshot = proxy.CreateSnapshot();

            Assert.AreEqual(OriginalTitle, proxy.Tittle);

            proxy.ChangeTitle(ChangedTitle);
            Assert.AreEqual(ChangedTitle, proxy.Tittle);

            proxy.RestoreFromSnapshot(snapshot);
            Assert.AreEqual(OriginalTitle, proxy.Tittle);
        }
Ejemplo n.º 5
0
        public void CodeSharp_to_Taobao_Adapter()
        {
            var c = new Castle.Windsor.WindsorContainer();

            //replace default IRemoteHandle
            c.Register(Component
                .For<C_NSF.Interfaces.IRemoteHandle>()
                .ImplementedBy<ServiceFrameworkAdapter.RemotingHandle>()
                .IsDefault());
            //Or
            //Use CodeSharp.Framework
            //CodeSharp.Framework.Configuration.Config().Castle().NSFAdapter();

            CodeSharp.ServiceFramework.Configuration
                .Configure()
                .Castle(c)
                .Associate(new Uri("tcp://taobao-dev-ntfe01:1234/remote.rem"))
                .Endpoint()
                .Run();

            var i = 0;
            while (i++ < 5)
                c.Resolve<Taobao.Facades.IUserService>().GetUserByDisplayName("侯昆");

            System.Threading.Thread.Sleep(5000);
        }
Ejemplo n.º 6
0
        static void Main()
        {
            var container = new Castle.Windsor.WindsorContainer();

            container.AddFacility <TypedFactoryFacility>();

            container.Install(new LogInstaller());

            container.Register(
                Component.For <IIntegrationEventHandlerFactory>().AsFactory(new IntegrationEventHandlerComponentSelector()),

                Component.For <IEventBusSubscriptionsManager>()
                .ImplementedBy <InMemoryEventBusSubscriptionsManager>(),

                Component.For <IRabbitMQPersistentConnection>()
                .ImplementedBy <DefaultRabbitMQPersistentConnection>(),


                Component.For <IEventBus>()
                .ImplementedBy <EventBusRabbitMQ>());

            var x = container.Resolve <IEventBus>();

            while (Console.ReadLine() != "exit")
            {
                for (int i = 0; i < 10; i++)
                {
                    x.Publish(new TestIntegrationEvent());
                }
            }

            container.Dispose();
        }
Ejemplo n.º 7
0
        public void CodeSharp_to_Taobao_Adapter()
        {
            var c = new Castle.Windsor.WindsorContainer();

            //replace default IRemoteHandle
            c.Register(Component
                       .For <C_NSF.Interfaces.IRemoteHandle>()
                       .ImplementedBy <ServiceFrameworkAdapter.RemotingHandle>()
                       .IsDefault());
            //Or
            //Use CodeSharp.Framework
            //CodeSharp.Framework.Configuration.Config().Castle().NSFAdapter();

            CodeSharp.ServiceFramework.Configuration
            .Configure()
            .Castle(c)
            .Associate(new Uri("tcp://taobao-dev-ntfe01:1234/remote.rem"))
            .Endpoint()
            .Run();

            var i = 0;

            while (i++ < 5)
            {
                c.Resolve <Taobao.Facades.IUserService>().GetUserByDisplayName("侯昆");
            }

            System.Threading.Thread.Sleep(5000);
        }
 static void Main(string[] args)
 {
     try
     {
         var container = new Castle.Windsor.WindsorContainer();
         container.Register
         (
             Component
             .For <Restricted>()
             .UsingFactoryMethod
             (
                 (k, c) =>
         {
             var requestingType = c.Handler.ComponentModel.Implementation;
             if (requestingType == typeof(Allowed))
             {
                 return(new RestrictedImp());
             }
             else
             {
                 var errorMessage = string.Format
                                    (
                     "The type [{0}] is not permitted to resolve [{1}].",
                     requestingType.Name,
                     c.RequestedType.Name
                                    );
                 throw new InvalidOperationException(errorMessage);
             }
         }
             )
             .LifeStyle
             .Transient
         );
         container.Register(Component.For <Allowed>());
         container.Register(Component.For <Disallowed>());
         var a = container.Resolve <Allowed>();
         var b = container.Resolve <Disallowed>();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
     Console.ReadLine();
 }
Ejemplo n.º 9
0
        public void Test1()
        {
            Castle.Windsor.IWindsorContainer windsorContainer = new Castle.Windsor.WindsorContainer();
            windsorContainer.AddAspectCoreFacility();
            windsorContainer.Register(Castle.MicroKernel.Registration.Component.For <IService>().ImplementedBy <Service>());
            windsorContainer.BeginScope();
            var s = windsorContainer.Resolve <IService>();

            s.Foo();
        }
Ejemplo n.º 10
0
        public static IEnumerable <object[]> GetContainerAdapters()
        {
            yield return(new object[] { (ResolverFactory)(c =>
                {
                    var container = new DefaultServiceContainer();
                    c(container);
                    return container.Resolve <IServiceResolver>();
                }) });

            yield return(new object[] { (ResolverFactory)(c =>
                {
                    var container = new LightInjectContainer();
                    c(new LightInjectAdapter(container));
                    return container.GetInstance <IServiceResolver>();
                }) });

            yield return(new object[] { (ResolverFactory)(c =>
                {
                    var container = new SimpleInjectorContainer {
                        Options = { AllowOverridingRegistrations = true }
                    };
                    c(new SimpleInjectorAdapter(container));
                    return container.GetInstance <IServiceResolver>();
                }) });

            yield return(new object[] { (ResolverFactory)(c =>
                {
                    var container = new StructureMapContainer(r => c(new StructureMapAdapter(r)));
                    return container.GetInstance <IServiceResolver>();
                }) });

            yield return(new object[] { (ResolverFactory)(c =>
                {
                    var containerBuilder = new ContainerBuilder();
                    c(new AutofacAdapter(containerBuilder));
                    var container = containerBuilder.Build();
                    return container.Resolve <IServiceResolver>();
                }) });

#if NETFX
            yield return(new object[] { (ResolverFactory)(c =>
                {
                    var container = new WindsorContainer();
                    c(new WindsorAdapter(container));
                    return container.Resolve <IServiceResolver>();
                }) });

            yield return(new object[] { (ResolverFactory)(c =>
                {
                    var container = new NinjectContainer();
                    c(new NinjectAdapter(container));
                    return container.Get <IServiceResolver>();
                }) });
#endif
        }
Ejemplo n.º 11
0
        public void Config()
        {
            var c = new Castle.Windsor.WindsorContainer();
            var endpoint = CodeSharp.ServiceFramework.Configuration
                .Configure()
                .Castle(c)
                .Log4Net(true)
                .Associate(new Uri(System.Configuration.ConfigurationManager.AppSettings["CenterUri"]))
                .Identity(new CodeSharp.ServiceFramework.Identity() { Source = "NTFE-BPM", AuthKey = "75DC6B572D1B940E34159DCD7FF26D8D" })
                .Endpoint();
            endpoint.Run();

            this._log = endpoint.Resolve<ILoggerFactory>().Create(this.GetType());
            this._clientApi = c.Resolve<Taobao.Workflow.Activities.Client.ITFlowEngine>();
            this._managementApi = c.Resolve<Taobao.Workflow.Activities.Management.ITFlowEngine>();

            //NTFE使用ID作为账号库用户名
            //UDONE:由于人员服务未做mock,因此目前取固定值
            this._originator = "5FE9A969-7CB2-4BA7-9601-E11473E8B233";//this.GetMappedUserId(this._originator).ToString();
            this._superior = "9D23EAA9-6145-4635-A7C2-D8AEEDF45C1E";//this.GetMappedUserId(this._superior).ToString();
        }
Ejemplo n.º 12
0
        public void Sample()
        {
            var container = new Castle.Windsor.WindsorContainer();

            container.Register(Castle.MicroKernel.Registration.Component
                               .For <ILogger>()
                               .ImplementedBy <ConsoleLogger>());
            ILogger logger = container.Resolve <ILogger>();

            container.Register(Castle.MicroKernel.Registration.Types
                               .FromThisAssembly()
                               .BasedOn <ILogger>());
        }
Ejemplo n.º 13
0
        public void Test1()
        {
            Castle.Windsor.IWindsorContainer windsorContainer = new Castle.Windsor.WindsorContainer();
            windsorContainer.AddAspectCoreFacility(config =>
            {
                config.Interceptors.AddDelegate((ctx, next) =>
                {
                    var scopedService = ctx.ServiceProvider.GetService(typeof(ScopedService));
                    return(ctx.Invoke(next));
                });
            });
            windsorContainer.AddAspectCoreFacility();
            windsorContainer.Register(Component.For <IService>().ImplementedBy <Service>());
            windsorContainer.Register(Component.For <ScopedService>().LifestyleScoped());
            windsorContainer.BeginScope();
            var s = windsorContainer.Resolve <IService>();

            s.Foo();
            windsorContainer.BeginScope();
            s = windsorContainer.Resolve <IService>();
            s.Foo();
        }
    private static void Main(string[] args)
    {
        var container = new Castle.Windsor.WindsorContainer();

        container.Register(Component.For <EventuallyRegisteredInterceptor>());
        container.Register(Component.For <IEventuallyRegistered>().ImplementedBy <DefaultRegistration>());
        // I'm not doing the optional registration, I just want to
        // demonstrate upgrading a additional configuration

        var t = container.Resolve <IEventuallyRegistered>();

        t.test();
    }
Ejemplo n.º 15
0
        public static void Run()
        {
            var container = new Castle.Windsor.WindsorContainer();

            container.Register(Component.For <Interceptor>());
            container.Register(
                Component
                .For <ICreditCardService>()
                .Interceptors <Interceptor>()
                .ImplementedBy <CreditCardService>()
                );
            var cardService = container.Resolve <ICreditCardService>();

            cardService.Charge(10, "123");
            Console.ReadKey();
        }
    private static void Main(string[] args)
    {
        var container = new Castle.Windsor.WindsorContainer();

        container.AddFacility <TypedFactoryFacility>();

        container.Register(
            Classes.FromAssemblyInThisApplication()
            .BasedOn(typeof(IModulePart <>))
            .WithService.Base()
            .LifestyleTransient(),
            Component.For <IModulePartFactory>().AsFactory()
            );
        var factory         = container.Resolve <IModulePartFactory>();
        var moduleForWebUrl = factory.FindModulePartFor <WebUrl>();
        // type is WebUrlModule
        var moduleForStockDelay = factory.FindModulePartFor <StockDelay>();
        // type is StockDelayModule
    }
Ejemplo n.º 17
0
        public static void Run()
        {
            var container = new Castle.Windsor.WindsorContainer();

            container.Register(Component
                               .For <LimitedScopeServce>()
                               .ImplementedBy <LimitedScopeServce>()
                               .LifestyleTransient()
                               );

            // chcemy aby LimitedScopeServce
            var scope = container.BeginScope();

            container.Resolve <LimitedScopeServce>();
            // ale tu już
            scope.Dispose();
            Console.WriteLine("Po scope");

            Console.ReadLine();
        }
        public void CanRestoreFormDynamicSnapshot()
        {
            //  We assert in each step!!!

            var target = Assembly.LoadFrom("Ncqrs.Eventing.Sourcing.Snapshotting.DynamicSnapshot.Tests.dll");
            var snapshotsAsm = DynamicSnapshot.CreateAssemblyFrom(target);

            Castle.Windsor.IWindsorContainer container = new Castle.Windsor.WindsorContainer();
            container.Register(Component.For<Foo>().AsSnapshotable());

            dynamic proxy = container.Resolve<Foo>();
            proxy.ChangeTitle(OriginalTitle);
            Assert.AreEqual(OriginalTitle, proxy.Tittle);

            var snapshot = proxy.CreateSnapshot();
            Assert.AreEqual(OriginalTitle, proxy.Tittle);

            proxy.ChangeTitle(ChangedTitle);
            Assert.AreEqual(ChangedTitle, proxy.Tittle);

            proxy.RestoreFromSnapshot(snapshot);
            Assert.AreEqual(OriginalTitle, proxy.Tittle);
        }
Ejemplo n.º 19
0
 public object Resolve(string componentName)
 {
     return(Instance.Resolve <object>(componentName, new Dictionary <string, string>()));
 }
 public T Resolve <T>()
 {
     return(_windsorContainer.Resolve <T>());
 }
Ejemplo n.º 21
0
        public void Automapping_For_Repository_Found()
        {
            object entity = _container.Resolve <IRepository <Animal> >();

            Assert.NotNull(entity);
        }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            IList <abc> abcs = new List <abc>()
            {
                new abc()
                {
                    A = "10", B = "a1", C = "100"
                },
                new abc()
                {
                    A = "11", B = "", C = "110"
                },
                new abc()
                {
                    A = "12", B = null, C = "120"
                },
                new abc()
                {
                    A = "13", B = "b1", C = "130"
                },
                new abc()
                {
                    A = "14", B = "c1", C = "140"
                },
                new abc()
                {
                    A = "Z", B = "X", C = "V"
                },
                new abc()
                {
                    A = "15", B = "d1", C = "150"
                }
            };

            IList <abc> list1 = new List <abc>()
            {
                new abc()
                {
                    A = "16", B = "a1", C = "100"
                },
                new abc()
                {
                    A = "17", B = null, C = "110"
                },
                new abc()
                {
                    A = "12", B = "", C = "120"
                },
                new abc()
                {
                    A = "18", B = "b1", C = "130"
                },
                new abc()
                {
                    A = "19", B = "c1", C = "140"
                },
                new abc()
                {
                    A = "20", B = "X", C = "V"
                },
                new abc()
                {
                    A = "15", B = "d1", C = "150"
                }
            };

            var objabc1 = abcs.Where(x => !string.IsNullOrEmpty(x.B));

            Console.WriteLine("B is null or empty:");
            foreach (var x in objabc1)
            {
                Console.WriteLine(x.A + "-" + x.B + "-" + x.C);
            }

            var objabc3 = abcs.FirstOrDefault(x => x.A == "13" && x.C == "130").C;

            Console.WriteLine("Use of Where Condition:");
            Console.WriteLine(objabc3);

            var result = abcs.SkipWhile(x => x.A != "Z")
                         .Skip(1)
                         .FirstOrDefault();

            Console.WriteLine("Use of skip:");
            Console.WriteLine(result.A + "-" + result.B + "-" + result.C);

            var result1 = abcs.Where(x => !string.IsNullOrEmpty(x.B)).TakeWhile(x => x.A != "Z")
                          .Take(3);
            var result2 = abcs.SkipWhile(x => x.A != "Z")
                          .Skip(1);
            var sum = result1.Concat(result2).Sum(x => Convert.ToInt32(x.C));

            Console.WriteLine("Sum of Column C:");
            Console.WriteLine(sum);

            var Group = abcs.GroupJoin(list1, x => x.A, A => A.A, (x, list) => new { gp = list, rs1 = x.A, rs2 = x.B, rs3 = x.C })
                        .Where(x => !string.IsNullOrEmpty(x.rs2));

            foreach (var item in Group)
            {
                Console.WriteLine(item.rs1);
                foreach (var items in item.gp)
                {
                    Console.WriteLine(items);
                }
            }

            //var (a, s) = AddAndSub(100, 200);

            string x1 = "India";

            //int z = 0, z1 = 0, z2 = 0;
            int a1 = 10, c1 = 50, n1 = 0, n2 = 0;

            //if (x == "India")
            //{
            //    z = a1 + c1;
            //    z1 = a1 + n1;
            //    z2 = a1 + n2;
            //}
            //else
            //{
            //    z = a1 * c1;
            //}

            var(x11, x2, x3) = x1 == "India"
                ? ((a1 + c1), (a1 + n1), (a1 + n2))
                : ((a1 * c1), 0, 0);
            Console.WriteLine("Question 5 Answer below:");
            Console.WriteLine(x11);

            //abc anotherExample = new abc();
            //anotherExample.ExampleMethod(1, optionalint: 5);


            ITest test = new Test();
            xyz   xyx  = new xyz(test);

            xyx.ValidateAll();

            var X = new Castle.Windsor.WindsorContainer();                        //Create Container

            X.Register(Component.For <IWindsorTest>().ImplementedBy <WINTest>()); //register the Interface and Class in which interface extended
            var res = X.Resolve <IWindsorTest>();                                 // resolve the Interface.

            res.getDetails();
            foreach (var n in res.getDetails())
            {
                Console.WriteLine("One interface and One Class:{0}", n);
            }

            //var X1 = new Castle.Windsor.WindsorContainer();//Create Container
            X.Register(Component.For <IWindsortest2>().ImplementedBy <Windsortest>()); //register the Interface and Class in which interface extended
            var res1 = X.ResolveAll <IWindsortest2>();                                 // resolve the Interface.
            int a = 40, b = 20;

            //res1.ADD(a,b);
            foreach (var res3 in res1)
            {
                Console.WriteLine(res3.ADD(a, b));
            }
            AddAndSub(50, 30);

            //var var1 = new Castle.Windsor.WindsorContainer();
            //X.Register(Component.For<IClass>().ImplementedBy<Class1>());
            //var res2 = X.Resolve<IClass>();
            //decimal p = 15, q = 18;
            //Console.WriteLine(res2.Multiply(p, q));


            Console.WriteLine("Reverse a string");
            string str21    = "i am going to market";
            string result21 = "";

            for (int i = str21.Length - 1; i >= 0; i--)
            {
                result21 += str21[i];
            }

            Console.WriteLine(result21);

            Console.WriteLine("Asyncronous task.");
            Call();

            abc ab = new abc();

            ab.A = "";
            Console.WriteLine(ab?.A ?? "Not available");

            CallerInfo();

            int      numeric   = default;
            Object   reference = default;
            DateTime value     = default;

            Console.WriteLine(numeric);

            Console.WriteLine(reference);
            Console.WriteLine(value);
        }