本文整理汇总了C#中LinFu.IoC.ServiceContainer.AutoCreate方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceContainer.AutoCreate方法的具体用法?C# ServiceContainer.AutoCreate怎么用?C# ServiceContainer.AutoCreate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinFu.IoC.ServiceContainer
的用法示例。
在下文中一共展示了ServiceContainer.AutoCreate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldAutoInjectClassCreatedWithAutoCreate
public void ShouldAutoInjectClassCreatedWithAutoCreate()
{
// Configure the container
var container = new ServiceContainer();
container.LoadFromBaseDirectory("*.dll");
var sampleService = new Mock<ISampleService>();
container.AddService(sampleService.Object);
var instance = (SampleClassWithInjectionProperties)container.AutoCreate(typeof(SampleClassWithInjectionProperties));
// The container should initialize the SomeProperty method to match the mock ISampleService instance
Assert.IsNotNull(instance.SomeProperty);
Assert.AreSame(instance.SomeProperty, sampleService.Object);
}
示例2: ContainerMustInjectFactoryInstances
public void ContainerMustInjectFactoryInstances()
{
var mockFactory = new Mock<IFactory<ISampleService>>();
mockFactory.Expect(f => f.CreateInstance(It.IsAny<IFactoryRequest>())).Returns(new SampleClass());
var container = new ServiceContainer();
container.AddFactory(mockFactory.Object);
var instance =
(SampleClassWithFactoryDependency) container.AutoCreate(typeof (SampleClassWithFactoryDependency));
Assert.IsNotNull(instance);
IFactory<ISampleService> factory = instance.Factory;
factory.CreateInstance(null);
mockFactory.VerifyAll();
}
示例3: ShouldInjectConstructorWithNamedParameterTypes
public void ShouldInjectConstructorWithNamedParameterTypes()
{
var mockDefaultSampleService = new Mock<ISampleService>();
var mockOtherSampleService = new Mock<ISampleService>();
var container = new ServiceContainer();
// Add the default service
container.AddService(mockDefaultSampleService.Object);
// Add the expected service instance
container.AddService("OtherService", mockOtherSampleService.Object);
var serviceInstance =
(SampleClassWithNamedParameters) container.AutoCreate(typeof (SampleClassWithNamedParameters));
Assert.AreEqual(mockOtherSampleService.Object, serviceInstance.ServiceInstance);
}
示例4: ShouldCreateTypeWithAdditionalParameters
public void ShouldCreateTypeWithAdditionalParameters()
{
var mockSampleService = new Mock<ISampleService>();
IServiceContainer container = new ServiceContainer();
// Add an ISampleService instance
container.AddService(mockSampleService.Object);
var resolver = container.GetService<IMemberResolver<ConstructorInfo>>();
Assert.IsNotNull(resolver);
var instance =
container.AutoCreate(typeof (SampleClassWithAdditionalArgument), 42) as
SampleClassWithAdditionalArgument;
Assert.IsNotNull(instance);
Assert.IsTrue(instance.Argument == 42);
}