本文整理汇总了C#中Registry.Scan方法的典型用法代码示例。如果您正苦于以下问题:C# Registry.Scan方法的具体用法?C# Registry.Scan怎么用?C# Registry.Scan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Registry
的用法示例。
在下文中一共展示了Registry.Scan方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindRegistriesWithinPluginGraphSeal
public void FindRegistriesWithinPluginGraphSeal()
{
var builder = new PluginGraphBuilder();
var registry = new Registry();
registry.Scan(x =>
{
x.AssemblyContainingType(typeof(RedGreenRegistry));
x.LookForRegistries();
});
builder.AddConfiguration(registry);
var graph = builder.Build();
var colors = new List<string>();
PluginFamily family = graph.FindFamily(typeof (IWidget));
family.Instances.Each(instance => colors.Add(instance.Name));
Assert.Contains("Red", colors);
Assert.Contains("Green", colors);
Assert.Contains("Yellow", colors);
Assert.Contains("Blue", colors);
Assert.Contains("Brown", colors);
Assert.Contains("Black", colors);
}
示例2: Generate
public INoobotContainer Generate()
{
var registry = new Registry();
registry.Scan(x =>
{
x.TheCallingAssembly();
x.WithDefaultConventions();
});
registry = _pipelineManager.Initialise(registry);
registry = _pluginManager.Initialise(registry);
registry
.For<ISlackWrapper>()
.Singleton();
registry
.For<IPipelineFactory>()
.Singleton();
Type[] pluginTypes = _pluginManager.ListPluginTypes();
var container = new NoobotContainer(registry, pluginTypes);
IPipelineFactory pipelineFactory = container.GetInstance<IPipelineFactory>();
pipelineFactory.SetContainer(container);
return container;
}
示例3: Test_Registry_Scan
public void Test_Registry_Scan()
{
Registry registry1 = new Registry();
registry1.Scan(scanner => {
// scanner.Assembly("FruitImplementations");
scanner.AssemblyContainingType<Output>();
scanner.WithDefaultConventions();
});
Container con1 = new Container(registry1);
IOutput output1 = con1.GetInstance<IOutput>();
IOutput output2 = con1.GetInstance<IOutput>();
Assert.AreNotSame(output1, output2);
}
示例4: SetUp
public void SetUp()
{
var registry = new Registry();
registry.For<Rule>();
registry.Scan(x => {
x.Assembly("StructureMap.Testing.Widget");
x.Assembly("StructureMap.Testing.Widget2");
});
var graph = registry.Build();
_session = BuildSession.ForPluginGraph(graph);
}
示例5: CreateRegistry
private static Registry CreateRegistry()
{
var registry = new Registry();
// setups DI for everything in Noobot.Core
registry.Scan(x =>
{
x.TheCallingAssembly();
x.WithDefaultConventions();
});
return registry;
}
示例6: ConfiguredInstanceTester
public ConfiguredInstanceTester()
{
var registry = new Registry();
registry.For<Rule>();
registry.Scan(x =>
{
x.Assembly("StructureMap.Testing.Widget");
x.Assembly("StructureMap.Testing.Widget2");
x.WithDefaultConventions();
});
var graph = registry.Build();
_session = BuildSession.ForPluginGraph(graph);
}
示例7: CanMakeAClassWithNoConstructorParametersWithoutADefinedMemento
public void CanMakeAClassWithNoConstructorParametersWithoutADefinedMemento()
{
var registry = new Registry();
registry.Scan(x => x.Assembly("StructureMap.Testing.Widget3"));
registry.BuildInstancesOf<IGateway>();
PluginGraph graph = registry.Build();
var pipelineGraph = new PipelineGraph(graph);
var session = new BuildSession(graph);
var gateway =
(DefaultGateway) session.CreateInstance(typeof (IGateway), "Default");
Assert.IsNotNull(gateway);
}
示例8: SetUp
public void SetUp()
{
var registry = new Registry();
registry.BuildInstancesOf<Rule>();
registry.Scan(x =>
{
x.Assembly("StructureMap.Testing.Widget");
x.Assembly("StructureMap.Testing.Widget2");
});
PluginGraph graph = registry.Build();
var pipelineGraph = new PipelineGraph(graph);
_session = new BuildSession(pipelineGraph, graph.InterceptorLibrary);
}
示例9: SetupMiddlewarePipeline
private void SetupMiddlewarePipeline(Registry registry)
{
Stack<Type> pipeline = GetPipelineStack();
registry.Scan(x =>
{
// scan assemblies that we are loading pipelines from
foreach (Type middlewareType in pipeline)
{
x.AssemblyContainingType(middlewareType);
}
});
registry.For<IMiddleware>().Use<UnhandledMessageMiddleware>();
// defined here so they can be overridden
registry.For<IMiddleware>().DecorateAllWith<AboutMiddleware>();
registry.For<IMiddleware>().DecorateAllWith<StatsMiddleware>();
while (pipeline.Any())
{
Type nextType = pipeline.Pop();
var nextDeclare = registry.For<IMiddleware>();
// using reflection as Structuremap doesn't allow passing types in at the moment :-(
MethodInfo decorateMethod = nextDeclare.GetType().GetMethod("DecorateAllWith", new[] { typeof(Func<Instance, bool>) });
MethodInfo generic = decorateMethod.MakeGenericMethod(nextType);
generic.Invoke(nextDeclare, new object[] { null });
}
if (_configReader.HelpEnabled())
{
registry.For<IMiddleware>().DecorateAllWith<HelpMiddleware>();
}
registry.For<IMiddleware>().DecorateAllWith<BeginMessageMiddleware>();
}
示例10: SetupPlugins
private Type[] SetupPlugins(Registry registry)
{
var pluginTypes = new List<Type>
{
typeof (StatsPlugin)
};
Type[] customPlugins = _configuration.ListPluginTypes() ?? new Type[0];
pluginTypes.AddRange(customPlugins);
registry.Scan(x =>
{
// scan assemblies that we are loading pipelines from
foreach (Type pluginType in pluginTypes)
{
x.AssemblyContainingType(pluginType);
x.WithDefaultConventions();
}
});
// make all plugins singletons
foreach (Type pluginType in pluginTypes)
{
registry
.For(pluginType)
.Singleton();
}
return pluginTypes.ToArray();
}
示例11: TheDefaultInstanceIsPickedUpFromTheAttribute
public void TheDefaultInstanceIsPickedUpFromTheAttribute()
{
var registry = new Registry();
registry.BuildInstancesOf<IGateway>();
registry.Scan(x => x.AssemblyContainingType<IGateway>());
PluginGraph pluginGraph = registry.Build();
Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway)));
var manager = new Container(pluginGraph);
var gateway = (IGateway) manager.GetInstance(typeof (IGateway));
Assert.IsInstanceOfType(typeof (DefaultGateway), gateway);
}
示例12: GotPluginsThatAreMarkedAsPluggable
public void GotPluginsThatAreMarkedAsPluggable()
{
var registry = new Registry();
registry.Scan(x => x.AssemblyContainingType<IWidget>());
registry.BuildInstancesOf<IWidget>();
PluginGraph pluginGraph = registry.Build();
PluginFamily pluginFamily = pluginGraph.FindFamily(typeof (IWidget));
Plugin plugin = pluginFamily.FindPlugin(typeof (ColorWidget));
Assert.IsNotNull(plugin);
}