本文整理汇总了C#中Registry.ForRequestedType方法的典型用法代码示例。如果您正苦于以下问题:C# Registry.ForRequestedType方法的具体用法?C# Registry.ForRequestedType怎么用?C# Registry.ForRequestedType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Registry
的用法示例。
在下文中一共展示了Registry.ForRequestedType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateServiceLocator
protected override IServiceLocator CreateServiceLocator() {
var registry = new Registry();
registry.ForRequestedType(typeof (ILogger))
.TheDefaultIsConcreteType(typeof (SimpleLogger))
.WithName(typeof (SimpleLogger).FullName);
registry
.ForRequestedType(typeof (ILogger))
.AddConcreteType(typeof (ComplexLogger),
typeof (ComplexLogger).FullName);
return new StructureMapServiceLocator(new Container(registry));
}
示例2: Return_the_same_object_within_a_session_for_the_default_of_a_plugin_type
public void Return_the_same_object_within_a_session_for_the_default_of_a_plugin_type()
{
int count = 0;
var instance = new LambdaInstance<ColorRule>(() =>
{
count++;
return new ColorRule("Red");
});
var registry = new Registry();
registry.ForRequestedType<ColorRule>().TheDefault.IsThis(instance);
PluginGraph graph = registry.Build();
var session = new BuildSession(graph);
object result1 = session.CreateInstance(typeof (ColorRule));
object result2 = session.CreateInstance(typeof (ColorRule));
object result3 = session.CreateInstance(typeof (ColorRule));
object result4 = session.CreateInstance(typeof (ColorRule));
Assert.AreEqual(1, count);
Assert.AreSame(result1, result2);
Assert.AreSame(result1, result3);
Assert.AreSame(result1, result4);
}
示例3: SetUp
public void SetUp()
{
var registry = new Registry();
registry.ForRequestedType(typeof (IService<>))
.AddConcreteType(typeof (Service<>))
.AddConcreteType(typeof (Service2<>));
registry.BuildInstancesOf<ISomething>()
.TheDefaultIsConcreteType<SomethingOne>()
.AddConcreteType<SomethingTwo>();
registry.BuildInstancesOf<IServiceProvider>().AddConcreteType<MyDataSet>().AddConcreteType<MyDataView>();
PluginGraph graph = registry.Build();
var pipeline = new PipelineGraph(graph);
_model = new Container(graph).Model;
_container = new Container(graph);
}
示例4: ConfigureRegistry
public void ConfigureRegistry(Registry registry)
{
registry.ForRequestedType<IValidate>().TheDefault.IsThis(_validationConfiguration);
}