本文整理汇总了C#中LinFu.IoC.ServiceContainer.LoadFromBaseDirectory方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceContainer.LoadFromBaseDirectory方法的具体用法?C# ServiceContainer.LoadFromBaseDirectory怎么用?C# ServiceContainer.LoadFromBaseDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinFu.IoC.ServiceContainer
的用法示例。
在下文中一共展示了ServiceContainer.LoadFromBaseDirectory方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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);
}
示例4: ShouldBeAbleToRedirectInterfaceCallToTarget
public void ShouldBeAbleToRedirectInterfaceCallToTarget()
{
var container = new ServiceContainer();
container.LoadFromBaseDirectory("*.dll");
// The duck should call the implementation instance
var mock = new Mock<SampleDuckTypeImplementation>();
mock.Expect(i => i.DoSomething());
object target = mock.Object;
var sampleService = target.CreateDuck<ISampleService>();
sampleService.DoSomething();
mock.VerifyAll();
}
示例5: ShouldBeAbleToInstantiateCustomFactoryWithServiceArgumentsInConstructor
public void ShouldBeAbleToInstantiateCustomFactoryWithServiceArgumentsInConstructor()
{
var mock = new Mock<ISampleService>();
var container = new ServiceContainer();
container.LoadFromBaseDirectory("*.dll");
container.AddService(mock.Object);
var result = container.GetService<string>("SampleFactoryWithConstructorArguments");
Assert.IsNotNull(result);
Assert.IsNotEmpty(result);
}