本文整理汇总了C#中Registry.For方法的典型用法代码示例。如果您正苦于以下问题:C# Registry.For方法的具体用法?C# Registry.For怎么用?C# Registry.For使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Registry
的用法示例。
在下文中一共展示了Registry.For方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: ConfigureModuleSpecificDependencies
private static void ConfigureModuleSpecificDependencies(Registry registry)
{
registry.For<IMasslogConfiguration>().Singleton().Use<LoggingConfiguration>();
registry.For<ILoggingConfiguration>().Singleton().Use<LoggingConfiguration>();
registry.For<IMonitorBehaviorFactory>().Singleton().Use<MonitorBehaviorFactory>();
registry.For<IMonitor>().HttpContextScoped().Use<Monitor>();
}
示例3: RegisterCommand
public void RegisterCommand(Registry registry)
{
var openCommandMethodResultType = typeof(CommandResult<>);
var closedCommandMethodResultType = openCommandMethodResultType.MakeGenericType(CommandType);
var openActionMethodInvokerType = typeof(IActionMethodResultInvoker<>);
var closedActionMethodInvokerType =
openActionMethodInvokerType.MakeGenericType(closedCommandMethodResultType);
var closedDomainResultType = typeof(CommandResult);
var openCommandMethodResultInvokerType = typeof(ResultInvoker<,>);
var closedCommandMethodResultInvokerType =
openCommandMethodResultInvokerType.MakeGenericType(closedCommandMethodResultType, closedDomainResultType);
registry.For(closedActionMethodInvokerType).Use(closedCommandMethodResultInvokerType);
var openResultProcessor = typeof(IResultProcessor<,>);
var closedResultProcessor =
openResultProcessor.MakeGenericType(closedCommandMethodResultType, closedDomainResultType);
var openCommandMethodResultProcessorType = typeof(CommandResultProcessor<>);
var closedCommandMethodResultProcessorType =
openCommandMethodResultProcessorType.MakeGenericType(CommandType);
registry.For(closedResultProcessor).Use(closedCommandMethodResultProcessorType);
}
示例4: LoadApplicationBusImplementations
private static void LoadApplicationBusImplementations(Registry registry)
{
registry.For<IApplicationBus>()
.Singleton().Use<ApplicationBus>();
registry.For<IMessageHandlerFactory>()
.Use<StructureMapMessageHandlerFactory>();
}
示例5: Process
public void Process(Type type, Registry registry) {
if (type.CanBeCastTo<Controller>() && !type.IsAbstract) {
registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());
}
else if (type.CanBeCastTo<ApiController>() && !type.IsAbstract)
{
registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());
}
}
示例6: CreateServiceLocator
protected override IServiceLocator CreateServiceLocator()
{
var registry = new Registry();
registry.For<ILogger>().Use<AdvancedLogger>();
registry.For<ILogger>().Use(new SimpleLogger()).Named(typeof(SimpleLogger).FullName);
registry.For<ILogger>().Use(new AdvancedLogger()).Named(typeof(AdvancedLogger).FullName);
IContainer container = new Container(registry);
return new StructureMapAdapter(container);
}
示例7: RegisterDependencies
public static Registry RegisterDependencies()
{
if (_hasBeenCalled) return _registry;
_registry = new Registry();
_registry.For<IEnvironment>().Use<Environment>();
_registry.For<IDatabaseConnection>().Use<DatabaseConnection>();
_hasBeenCalled = true;
return _registry;
}
示例8: Test_Singleton
public void Test_Singleton()
{
Registry registry1 = new Registry();
registry1.For<IOutput>().Use<Output>().Singleton();
registry1.For<IFruit>().Use<Apple>();
Container con1 = new Container(registry1);
IOutput output1 = con1.GetInstance<IOutput>();
IOutput output2 = con1.GetInstance<IOutput>();
Assert.AreSame(output1, output2);
}
示例9: RegisterDependencies
public static Registry RegisterDependencies()
{
if (_hasBeenCalled) return _registry;
_registry = new Registry();
_registry.For<IDatabaseServices>().Use<DatabaseServices>();
_registry.For<IDatabaseSetting>().Use<DatabaseSetting>();
_registry.For<IDatabaseConnection>().Use<DatabaseConnection>();
_hasBeenCalled = true;
return _registry;
}
示例10: Process
public void Process(Type type, Registry registry)
{
if (!type.IsSubclassOf(typeof(Entity))) return;
var openQueryModelBinder = typeof (QueryableModelBinder<>);
var closedQueryModelBinder = openQueryModelBinder.MakeGenericType(type);
var openIdToEntityModelBinder = typeof (IdToEntityModelBinder<>);
var closedIdToEntityModelBinder = openIdToEntityModelBinder.MakeGenericType(type);
registry.For(typeof(IFilteredModelBinder)).Use(closedQueryModelBinder);
registry.For(typeof(IFilteredModelBinder)).Use(closedIdToEntityModelBinder);
}
示例11: ScanTypes
public void ScanTypes(TypeSet types, Registry registry)
{
foreach(var type in types.FindTypes(TypeClassification.Concretes | TypeClassification.Closed))
{
if (type.CanBeCastTo<Controller>() && !type.IsAbstract)
{
registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());
}
else if (type.CanBeCastTo<ApiController>() && !type.IsAbstract)
{
registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());
}
}
}
示例12: Process
public void Process(Type type, Registry registry)
{
// Only work on concrete types
if (!type.IsConcrete() || type.IsGenericType) return;
// Add against all the interfaces implemented
// by this concrete class
type.GetInterfaces()
.Where(@interface => @interface.Name == $"I{type.Name}" )
.ForEach(@interface => registry.For(@interface).Use(type).Singleton());
if (type.Name.EndsWith("Job"))
registry.For(type).Singleton();
}
示例13: ScanTypes
public void ScanTypes(TypeSet types, Registry registry)
{
// Only work on concrete types
types.FindTypes(TypeClassification.Concretes | TypeClassification.Closed).ForEach(type =>
{
type.GetInterfaces()
.Where(@interface => @interface.Name == $"I{type.Name}")
.ForEach(@interface => registry.For(@interface).Use(type).Singleton());
if (type.Name.EndsWith("Job"))
registry.For(type).Singleton();
});
}
示例14: Apply
public void Apply(PluginGraph graph)
{
var registry = new Registry();
_interfaces.Each(@interface =>
{
var expression = registry.For(@interface);
ConfigureFamily(expression);
var exactMatches = _concretions.Where(x => x.CanBeCastTo(@interface)).ToArray();
if (exactMatches.Length == 1)
{
expression.Use(exactMatches.Single());
}
else
{
exactMatches.Each(type => expression.Add(type));
}
if ([email protected]())
{
addConcretionsThatCouldBeClosed(@interface, expression);
}
});
_concretions.Each(t => graph.ConnectedConcretions.Fill(t));
registry.As<IPluginGraphConfiguration>().Configure(graph);
}
示例15: Test_GetAllInstances
public void Test_GetAllInstances()
{
Registry registry1 = new Registry();
registry1.For<IOutput>().Use<Output>().Singleton();
registry1.For<IFruit>().Use<Apple>();
Container con1 = new Container(registry1);
Type t1 = typeof(IOutput);
Assert.AreEqual(1, ConvertToList(con1, t1).Count);
Assert.AreEqual(1, ConvertToList(con1, t1).Count);
Type t2 = typeof(Apple);
Assert.AreEqual(0, ConvertToList(con1, t2).Count);
Assert.AreEqual(0, ConvertToList(con1, t2).Count);
}