当前位置: 首页>>代码示例>>C#>>正文


C# ServiceContainer.LoadFrom方法代码示例

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


在下文中一共展示了ServiceContainer.LoadFrom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: Main

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

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

            IVehicle vehicle = container.GetService<IVehicle>();

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

示例6: ShouldAutoInjectMethod

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

            var instance = new SampleClassWithInjectionMethod();

            // Initialize the container
            container.Inject<ISampleService>().Using<SampleClass>().OncePerRequest();
            container.Inject<ISampleService>("MyService").Using(c => instance).OncePerRequest();

            var result = container.GetService<ISampleService>("MyService");
            Assert.AreSame(result, instance);

            // On initialization, the instance.Property value
            // should be a SampleClass type
            Assert.IsNotNull(instance.Property);
            Assert.IsInstanceOfType(typeof(SampleClass), instance.Property);
        }
开发者ID:sdether,项目名称:LinFu,代码行数:19,代码来源:MethodInjectionTests.cs

示例7: AroundInvokeClassesMarkedWithInterceptorAttributeMustGetActualTargetInstance

        public void AroundInvokeClassesMarkedWithInterceptorAttributeMustGetActualTargetInstance()
        {
            var container = new ServiceContainer();
            container.LoadFrom(AppDomain.CurrentDomain.BaseDirectory, "*.dll");
            var mockService = new Mock<ISampleWrappedInterface>();
            mockService.Expect(mock => mock.DoSomething());

            // Add the target instance
            container.AddService(mockService.Object);

            // The service must return a proxy
            var service = container.GetService<ISampleWrappedInterface>();
            Assert.AreNotSame(service, mockService.Object);

            // Execute the method and 'catch' the target instance once the method call is made
            service.DoSomething();

            var holder = container.GetService<ITargetHolder>("SampleAroundInvokeInterceptorClass");
            Assert.AreSame(holder.Target, mockService.Object);
        }
开发者ID:svgorbunov,项目名称:ScrollsModLoader,代码行数:20,代码来源:InversionOfControlTests.cs

示例8: Main

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

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

            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:jam231,项目名称:LinFu,代码行数:21,代码来源:Program.cs

示例9: ShouldAutoInjectPropertyWithoutCustomAttribute

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

            var instance = new SampleClassWithUnmarkedInjectionProperties();

            // Initialize the container with the dummy service
            container.Inject<ISampleService>().Using<SampleClass>().OncePerRequest();
            container.Inject<ISampleService>("MyService").Using(c => instance).OncePerRequest();

            // Enable automatic property injection for every property
            container.SetCustomPropertyInjectionAttribute(null);

            // Get the service instance
            var result = container.GetService<ISampleService>("MyService");
            Assert.AreSame(result, instance);

            // Ensure that the injection occurred
            Assert.IsNotNull(instance.SomeProperty);
            Assert.IsInstanceOfType(typeof(SampleClass), instance.SomeProperty);
        }
开发者ID:sdether,项目名称:LinFu,代码行数:22,代码来源:PropertyInjectionTests.cs

示例10: Main

        static void Main()
        {
            #region LinFu

            //создаем LinFu IoC контейнер
            var container = new ServiceContainer();
            //настраиваем контейнер
            container.LoadFrom(AppDomain.CurrentDomain.BaseDirectory, "Logger.dll");

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //Для хранилища SQL Server
            Application.Run(new Form1(container.GetService<ISqlRepository>()));

            //Для хранилища XML файл
            //Application.Run(new Form1(container.GetService<IXmlRepository>()));

            #endregion

            #region Unity

            ////создаем IoC Unity
            //IUnityContainer container = new UnityContainer();

            ////Для хранилища SQL Server
            //container.RegisterType(typeof(IRepository), typeof(EFRepository));

            ////Для хранилища XML файл
            //container.RegisterType(typeof(IRepository), typeof(XmlRepository));

            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(container.Resolve<Form1>());

            #endregion
        }
开发者ID:ringill,项目名称:Calculator_01,代码行数:37,代码来源:Program.cs

示例11: ContainerMustLoadAssemblyFromMemory

        public void ContainerMustLoadAssemblyFromMemory()
        {
            var container = new ServiceContainer();
            container.LoadFrom(typeof (SampleClass).Assembly);

            // Verify that the container loaded the sample assembly into memory
            Assert.IsTrue(container.Contains(typeof (ISampleService)));
        }
开发者ID:svgorbunov,项目名称:ScrollsModLoader,代码行数:8,代码来源:InversionOfControlTests.cs

示例12: ServiceContainer

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

            string serviceName = "NonSpecificGenericService";

            // The container must be able to create any type that derives from ISampleService<T>
            // despite whether or not the specific generic service type is explicitly registered as a service
            Assert.IsTrue(container.Contains(serviceName, typeof (ISampleGenericService<int>)));
            Assert.IsTrue(container.Contains(serviceName, typeof (ISampleGenericService<double>)));
            Assert.IsTrue(container.Contains(serviceName, typeof (ISampleGenericService<string>)));

            // Both service types must be valid services
            Assert.IsNotNull(container.GetService<ISampleGenericService<int>>());
            Assert.IsNotNull(container.GetService<ISampleGenericService<double>>());
            Assert.IsNotNull(container.GetService<ISampleGenericService<string>>());
        }
开发者ID:svgorbunov,项目名称:ScrollsModLoader,代码行数:18,代码来源:InversionOfControlTests.cs

示例13: ContainerMustGracefullyHandleRecursiveServiceDependencies

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

            container.AddService(typeof (SampleRecursiveTestComponent1), typeof (SampleRecursiveTestComponent1));
            container.AddService(typeof (SampleRecursiveTestComponent2), typeof (SampleRecursiveTestComponent2));

            try
            {
                var result = container.GetService<SampleRecursiveTestComponent1>();
            }
            catch (Exception ex)
            {
                Assert.IsNotInstanceOfType(typeof (StackOverflowException), ex);
            }
        }
开发者ID:svgorbunov,项目名称:ScrollsModLoader,代码行数:17,代码来源:InversionOfControlTests.cs

示例14: ShouldBeAbleToCreateClosedGenericTypeUsingACustomFactoryInstance

        public void ShouldBeAbleToCreateClosedGenericTypeUsingACustomFactoryInstance()
        {
            var container = new ServiceContainer();
            container.Initialize();
            container.LoadFrom(typeof (MyClass<>).Assembly);

            // Get ServiceNotFoundException here instead of a service instance.
            string serviceName = "frobozz";
            var service = container.GetService<MyClass<string>>(serviceName);

            Console.WriteLine("foo");
            Assert.AreEqual(serviceName, service.Value);
        }
开发者ID:svgorbunov,项目名称:ScrollsModLoader,代码行数:13,代码来源:FactoryTests.cs

示例15: ContainerMustCallIInitializeOnServicesCreatedFromCustomFactory

        public void ContainerMustCallIInitializeOnServicesCreatedFromCustomFactory()
        {
            var mockFactory = new Mock<IFactory>();
            var mockInitialize = new Mock<IInitialize>();

            mockFactory.Expect(f => f.CreateInstance(It.IsAny<IFactoryRequest>()))
                .Returns(mockInitialize.Object);

            // The IInitialize instance must be called once it
            // leaves the custom factory
            mockInitialize.Expect(i => i.Initialize(It.IsAny<IServiceContainer>()));

            var container = new ServiceContainer();
            container.LoadFrom(AppDomain.CurrentDomain.BaseDirectory, "LinFu*.dll");
            container.AddFactory(typeof (IInitialize), mockFactory.Object);

            var result = container.GetService<IInitialize>();

            mockFactory.VerifyAll();
            mockInitialize.VerifyAll();
        }
开发者ID:svgorbunov,项目名称:ScrollsModLoader,代码行数:21,代码来源:InversionOfControlTests.cs


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