本文整理汇总了C#中LinFu.IoC.ServiceContainer.AddDefaultServices方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceContainer.AddDefaultServices方法的具体用法?C# ServiceContainer.AddDefaultServices怎么用?C# ServiceContainer.AddDefaultServices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinFu.IoC.ServiceContainer
的用法示例。
在下文中一共展示了ServiceContainer.AddDefaultServices方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: ShouldResolveConstructorWithMostResolvableParametersFromContainer
public void ShouldResolveConstructorWithMostResolvableParametersFromContainer()
{
var mockSampleService = new Mock<ISampleService>();
IServiceContainer container = new ServiceContainer();
// Add an ISampleService instance
container.AddService(mockSampleService.Object);
container.AddDefaultServices();
var resolver = container.GetService<IMemberResolver<ConstructorInfo>>();
Assert.IsNotNull(resolver);
// The resolver should return the constructor with two ISampleService parameters
var expectedConstructor =
typeof (SampleClassWithMultipleConstructors).GetConstructor(new[]
{
typeof (ISampleService),
typeof (ISampleService)
});
Assert.IsNotNull(expectedConstructor);
var finderContext = new MethodFinderContext(new Type[0], new object[0], null);
var result = resolver.ResolveFrom(typeof (SampleClassWithMultipleConstructors), container,
finderContext);
Assert.AreSame(expectedConstructor, result);
}
示例3: ShouldResolveConstructorWithAdditionalArgument
public void ShouldResolveConstructorWithAdditionalArgument()
{
var mockSampleService = new Mock<ISampleService>();
IServiceContainer container = new ServiceContainer();
// Add an ISampleService instance
container.AddService(mockSampleService.Object);
container.AddDefaultServices();
var resolver = container.GetService<IMemberResolver<ConstructorInfo>>();
Assert.IsNotNull(resolver);
// The resolver should return the constructor
// with the following signature: Constructor(ISampleService, int)
var expectedConstructor =
typeof (SampleClassWithAdditionalArgument).GetConstructor(new[] {typeof (ISampleService), typeof (int)});
Assert.IsNotNull(expectedConstructor);
var context = new MethodFinderContext(42);
var result = resolver.ResolveFrom(typeof (SampleClassWithAdditionalArgument), container, context);
Assert.AreSame(expectedConstructor, result);
}
示例4: ShouldResolveClassWithMultipleNonServiceArgumentConstructors
public void ShouldResolveClassWithMultipleNonServiceArgumentConstructors()
{
IServiceContainer container = new ServiceContainer();
container.AddDefaultServices();
container.AddService("ClassWithMultipleNonServiceArgumentConstructors",
typeof (ISampleService), typeof (SampleClassWithMultipleNonServiceArgumentConstructors),
LifecycleType.OncePerRequest);
// Match the correct constructor
var sampleService = container.GetService<ISampleService>("ClassWithMultipleNonServiceArgumentConstructors",
"test", 42, SampleEnum.One, (decimal) 3.14, 42);
Assert.IsNotNull(sampleService);
}
示例5: ShouldInstantiateObjectWithConstructorAndArguments
public void ShouldInstantiateObjectWithConstructorAndArguments()
{
var targetConstructor = typeof (SampleClassWithMultipleConstructors).GetConstructor(new[]
{
typeof
(
ISampleService
)
,
typeof
(
ISampleService
)
});
// Create the method arguments
var mockSampleService = new Mock<ISampleService>();
var arguments = new object[] {mockSampleService.Object, mockSampleService.Object};
// Initialize the container
IServiceContainer container = new ServiceContainer();
container.AddDefaultServices();
var constructorInvoke = container.GetService<IMethodInvoke<ConstructorInfo>>();
var result = constructorInvoke.Invoke(null, targetConstructor, arguments);
Assert.IsNotNull(result);
Assert.IsInstanceOfType(typeof (SampleClassWithMultipleConstructors), result);
}
示例6: ShouldInstantiateClassWithNonServiceArguments
public void ShouldInstantiateClassWithNonServiceArguments()
{
var container = new ServiceContainer();
container.AddDefaultServices();
container.AddService(typeof (SampleClassWithNonServiceArgument), typeof (SampleClassWithNonServiceArgument));
var text = "Hello, World!";
string serviceName = null;
var result = container.GetService<SampleClassWithNonServiceArgument>(serviceName, text);
Assert.IsNotNull(result);
Assert.IsTrue(result.Value == text);
}