• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IoC.ServiceContainer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中LinFu.IoC.ServiceContainer的典型用法代码示例。如果您正苦于以下问题:C# ServiceContainer类的具体用法?C# ServiceContainer怎么用?C# ServiceContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ServiceContainer类属于LinFu.IoC命名空间,在下文中一共展示了ServiceContainer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ScopeShouldNeverCallDisposableOnScopedObjectCreatedInAnotherThread

        public void ScopeShouldNeverCallDisposableOnScopedObjectCreatedInAnotherThread()
        {
            var mock = new Mock<IDisposable>();

            var container = new ServiceContainer();
            container.AddService(mock.Object);

            using (var scope = container.GetService<IScope>())
            {
                var signal = new ManualResetEvent(false);
                WaitCallback callback = state =>
                                            {
                                                // Create the service instance
                                                var instance = container.GetService<IDisposable>();
                                                signal.Set();
                                            };

                ThreadPool.QueueUserWorkItem(callback);

                // Wait for the thread to execute
                WaitHandle.WaitAny(new WaitHandle[] {signal});
            }

            // The instance should never be disposed
        }
开发者ID:svgorbunov,项目名称:ScrollsModLoader,代码行数:25,代码来源:ScopeTests.cs


示例2: TestPropertyInjection

        private static void TestPropertyInjection(string serviceName)
        {
            var mockTarget = new Mock<IInjectionTarget>();
            mockTarget.Expect(t => t.SetValue(123));
            var target = mockTarget.Object;

            var container = new ServiceContainer();
            container.AddService(serviceName, target);

            // Use the named fluent interface for
            // named instances
            if (!String.IsNullOrEmpty(serviceName))
            {
                container.Initialize<IInjectionTarget>(serviceName)
                    .With(service => service.SetValue(123));
            }
            else
            {
                // Otherwise, use the other one
                container.Initialize<IInjectionTarget>()
                    .With(service => service.SetValue(123));
            }
            var result = container.GetService<IInjectionTarget>(serviceName);
            Assert.IsNotNull(result);

            // The container should initialize the
            // service on every request
            mockTarget.VerifyAll();
        }
开发者ID:sdether,项目名称:LinFu,代码行数:29,代码来源:FluentPropertyInjectionTests.cs


示例3: LinFuAspectContainer

 public LinFuAspectContainer(ServiceContainer container)
 {
     Proxy = new MasterProxy();
     _container = container;
     _container.PostProcessors.Add(new AspectPostProcessor());
     _container.AddService(Proxy);
 }
开发者ID:JorgeGamba,项目名称:Snap,代码行数:7,代码来源:LinFuAspectContainer.cs


示例4: Init

 public static void Init()
 {
     ServiceContainer container = new ServiceContainer();
     container.AddService(typeof(IValidator), typeof(Validator));
     container.AddService(typeof(IEntityDuplicateChecker), typeof(EntityDuplicateCheckerStub));
     ServiceLocator.SetLocatorProvider(() => new LinFuServiceLocator(container));
 }
开发者ID:sztupy,项目名称:shaml,代码行数:7,代码来源:ServiceLocatorInitializer.cs


示例5: ShouldLoadAssemblyIntoLoaderAtRuntime

        public void ShouldLoadAssemblyIntoLoaderAtRuntime()
        {
            string path = Path.Combine(@"..\..\..\SampleFileWatcherLibrary\bin\Debug",
                                       AppDomain.CurrentDomain.BaseDirectory);
            string targetFile = "SampleFileWatcherLibrary.dll";
            string sourceFileName = Path.Combine(path, targetFile);

            var container = new ServiceContainer();
            container.AutoLoadFrom(AppDomain.CurrentDomain.BaseDirectory, "dummy.dll");

            // There should be nothing loaded at this point since the assembly hasn't
            // been copied to the target directory yet
            Assert.IsFalse(container.Contains(typeof (ISampleService)));

            // Copy the assembly to the target directory
            // and watch for changes
            string targetFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "dummy.dll");
            File.Copy(sourceFileName, targetFileName, true);

            // Give the watcher thread enough time to load the assembly into memory
            Thread.Sleep(500);
            Assert.IsTrue(container.Contains(typeof (ISampleService)));

            var instance = container.GetService<ISampleService>();
            Assert.IsNotNull(instance);

            string typeName = instance.GetType().Name;
            Assert.AreEqual("SampleFileWatcherServiceClassAddedAtRuntime", typeName);
        }
开发者ID:svgorbunov,项目名称:ScrollsModLoader,代码行数:29,代码来源:FileWatcherTests.cs


示例6: LinFuAspectContainer

 public LinFuAspectContainer(ServiceContainer container)
 {
     Proxy = new MasterProxy {Container = new LinFuServiceLocatorAdapter(container)};
     _container = container;
     _container.PostProcessors.Add(new AspectPostProcessor());
     _container.AddService(Proxy);
 }
开发者ID:nickspoons,项目名称:Snap,代码行数:7,代码来源:LinFuAspectContainer.cs


示例7: Main

        static void Main(string[] args)
        {
            string directory = AppDomain.CurrentDomain.BaseDirectory;
            IServiceContainer container = new ServiceContainer();

            // Load CarLibrary3.dll; If you need load
            // all the libaries in a directory, use "*.dll" instead
            container.LoadFrom(directory, "CarLibrary3.dll");

            // Configure the container inject instances
            // into the Car class constructor
            container.Inject<IVehicle>()
                .Using(ioc => new Car(ioc.GetService<IEngine>(),
                                      ioc.GetService<IPerson>()))
                                      .OncePerRequest();

            Person person = new Person();
            person.Name = "Someone";
            person.Age = 18;

            container.AddService<IPerson>(person);
            IVehicle vehicle = container.GetService<IVehicle>();

            vehicle.Move();

            Console.WriteLine("Press ENTER to continue...");
            Console.ReadLine();
        }
开发者ID:slieser,项目名称:LinFu,代码行数:28,代码来源:Program.cs


示例8: InitializeServiceLocator

        public static void InitializeServiceLocator()
        {
            ServiceContainer container = new ServiceContainer();
            AddComponentsTo(container);

            ControllerBuilder.Current.SetControllerFactory(new LinFuControllerFactory(container));
            ServiceLocator.SetLocatorProvider(() => new LinFuServiceLocator(container));
        }
开发者ID:sztupy,项目名称:CodeChirp,代码行数:8,代码来源:ComponentRegistrar.cs


示例9: Inject

 private static void Inject(string serviceName, Action<IGenerateFactory<ISampleService>> usingFactory,
                            Func<IUsingLambda<ISampleService>, IGenerateFactory<ISampleService>> doInject,
                            ServiceContainer container)
 {
     // HACK: Condense the fluent statements into a single,
     // reusable line of code
     usingFactory(doInject(container.Inject<ISampleService>(serviceName)));
 }
开发者ID:svgorbunov,项目名称:ScrollsModLoader,代码行数:8,代码来源:FluentExtensionTests.Implementation.cs


示例10: PrepareBasic

        public override void PrepareBasic()
        {
            this.container = new LinFu.IoC.ServiceContainer();

            this.RegisterDummies();
            this.RegisterStandard();
            this.RegisterComplex();
        }
开发者ID:CodeDux,项目名称:IocPerformance,代码行数:8,代码来源:LinFuContainerAdapter.cs


示例11: Prepare

 public override void Prepare()
 {
     this.container = new LinFu.IoC.ServiceContainer();
     this.container.Inject<ISingleton>().Using<Singleton>().AsSingleton();
     this.container.Inject<ITransient>().Using<Transient>().OncePerRequest();
     this.container.Inject<ICombined>().Using<Combined>().OncePerRequest();
     this.container.Inject<ICalculator>().Using<Calculator>().OncePerRequest();
 }
开发者ID:junxy,项目名称:IocPerformance,代码行数:8,代码来源:LinFuContainerAdapter.cs


示例12: Main

        static void Main(string[] args)
        {
            string directory = AppDomain.CurrentDomain.BaseDirectory;
            IServiceContainer container = new ServiceContainer();

            container.LoadFrom(directory, "*.dll");

            Console.WriteLine("Press ENTER to continue...");
            Console.ReadLine();
        }
开发者ID:leehavin,项目名称:linfu,代码行数:10,代码来源:Program.cs


示例13: Test

        private static void Test(string serviceName, Action<IGenerateFactory<ISampleService>> usingFactory, Func<IUsingLambda<ISampleService>, IGenerateFactory<ISampleService>> doInject, Func<string, IServiceContainer, bool> verifyResult)
        {
            var container = new ServiceContainer();

            // HACK: Manually inject the required services into the container
            container.AddDefaultServices();

            Inject(serviceName, usingFactory, doInject, container);
            verifyResult(serviceName, container);
        }
开发者ID:sdether,项目名称:LinFu,代码行数:10,代码来源:FluentExtensionTests.Implementation.cs


示例14: Prepare

        public override void Prepare()
        {
            this.container = new LinFu.IoC.ServiceContainer();

            this.RegisterDummies();
            this.RegisterStandard();
            this.RegisterComplex();
            this.RegisterMultiple();
            this.RegisterPropertyInjection();
        }
开发者ID:huangyingwen,项目名称:IocPerformance,代码行数:10,代码来源:LinFuContainerAdapter.cs


示例15: CanReturnServiceIfInitializedAndRegistered

        public void CanReturnServiceIfInitializedAndRegistered()
        {
            ServiceContainer container = new ServiceContainer();
            container.LoadFromBaseDirectory("Shaml.Data.dll");
            container.AddService("validator", typeof(IValidator), typeof(Validator), LinFu.IoC.Configuration.LifecycleType.OncePerRequest);

            ServiceLocator.SetLocatorProvider(() => new LinFuServiceLocator(container));

            IValidator validatorService = SafeServiceLocator<IValidator>.GetService();

            Assert.That(validatorService, Is.Not.Null);
        }
开发者ID:sztupy,项目名称:shaml,代码行数:12,代码来源:SafeServiceLocatorTests.cs


示例16: LinFu_Container_Allow_Wildcard_Matching

        public void LinFu_Container_Allow_Wildcard_Matching()
        {
            var container = new ServiceContainer();
            container.LoadFrom(AppDomain.CurrentDomain.BaseDirectory, "*.dll");

            SnapConfiguration.For(new LinFuAspectContainer(container)).Configure(c =>
            {
                c.IncludeNamespace("SnapTests.*");
                c.Bind<HandleErrorInterceptor>().To<HandleErrorAttribute>();
            });

            Assert.DoesNotThrow(() => container.GetService<IBadCode>());
        }
开发者ID:JorgeGamba,项目名称:Snap,代码行数:13,代码来源:LinFuTests.cs


示例17: ShouldFindGenericMethod

        public void ShouldFindGenericMethod()
        {
            var container = new ServiceContainer();
            container.LoadFromBaseDirectory("*.dll");

            var context = new MethodFinderContext(new Type[]{typeof(object)}, new object[0], typeof(void));
            var methods = typeof(SampleClassWithGenericMethod).GetMethods(BindingFlags.Public | BindingFlags.Instance);
            var finder = container.GetService<IMethodFinder<MethodInfo>>();
            var result = finder.GetBestMatch(methods, context);

            Assert.IsTrue(result.IsGenericMethod);
            Assert.IsTrue(result.GetGenericArguments().Count() == 1);
        }
开发者ID:leehavin,项目名称:linfu,代码行数:13,代码来源:MethodFinderTests.cs


示例18: Linfu

        public Linfu()
        {
            container = new ServiceContainer();
            container.AddService(typeof(Game), LifecycleType.Singleton);
            container.AddService(typeof(Player), LifecycleType.OncePerRequest);
            container.AddService(typeof(Gun), LifecycleType.OncePerRequest);
            container.AddService(typeof(Bullet), LifecycleType.OncePerRequest);
            container.AddService<Func<Bullet>>(r => () => r.Container.GetService<Bullet>(), LifecycleType.OncePerRequest);

            container.DisableAutoFieldInjection();
            container.DisableAutoMethodInjection();
            container.DisableAutoPropertyInjection();
        }
开发者ID:philiplaureano,项目名称:PaulTest,代码行数:13,代码来源:Linfu.cs


示例19: LinFu_Container_Fails_Without_Match

        public void LinFu_Container_Fails_Without_Match()
        {
            var container = new ServiceContainer();
            container.LoadFrom(AppDomain.CurrentDomain.BaseDirectory, "*.dll");

            SnapConfiguration.For(new LinFuAspectContainer(container)).Configure(c =>
            {
                c.IncludeNamespace("Does.Not.Work");
                c.Bind<HandleErrorInterceptor>().To<HandleErrorAttribute>();
            });

            Assert.Throws<NullReferenceException>(() => container.GetService<IBadCode>());
        }
开发者ID:JorgeGamba,项目名称:Snap,代码行数:13,代码来源:LinFuTests.cs


示例20: ScopeShouldCallDisposableOnScopedObject

        public void ScopeShouldCallDisposableOnScopedObject()
        {
            var mock = new Mock<IDisposable>();
            mock.Expect(disposable => disposable.Dispose());

            var container = new ServiceContainer();
            container.AddService(mock.Object);

            using (var scope = container.GetService<IScope>())
            {
                // Create the service instance
                var instance = container.GetService<IDisposable>();
            }
        }
开发者ID:svgorbunov,项目名称:ScrollsModLoader,代码行数:14,代码来源:ScopeTests.cs



注:本文中的LinFu.IoC.ServiceContainer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Datatypes.TalkException类代码示例发布时间:2022-05-26
下一篇:
C# LilyPath.Pen类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap