本文整理汇总了C#中LinFu.IoC.ServiceContainer.SetCustomPropertyInjectionAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceContainer.SetCustomPropertyInjectionAttribute方法的具体用法?C# ServiceContainer.SetCustomPropertyInjectionAttribute怎么用?C# ServiceContainer.SetCustomPropertyInjectionAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinFu.IoC.ServiceContainer
的用法示例。
在下文中一共展示了ServiceContainer.SetCustomPropertyInjectionAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}