本文整理汇总了C#中IInjector.GetNamedInstance方法的典型用法代码示例。如果您正苦于以下问题:C# IInjector.GetNamedInstance方法的具体用法?C# IInjector.GetNamedInstance怎么用?C# IInjector.GetNamedInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IInjector
的用法示例。
在下文中一共展示了IInjector.GetNamedInstance方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeAppArgsToBytes
internal byte[] SerializeAppArgsToBytes(AppParameters appParameters, IInjector paramInjector)
{
var avroAppSubmissionParameters = new AvroAppSubmissionParameters
{
tcpBeginPort = paramInjector.GetNamedInstance<TcpPortRangeStart, int>(),
tcpRangeCount = paramInjector.GetNamedInstance<TcpPortRangeCount, int>(),
tcpTryCount = paramInjector.GetNamedInstance<TcpPortRangeTryCount, int>()
};
var avroYarnAppSubmissionParameters = new AvroYarnAppSubmissionParameters
{
sharedAppSubmissionParameters = avroAppSubmissionParameters,
driverRecoveryTimeout = paramInjector.GetNamedInstance<DriverBridgeConfigurationOptions.DriverRestartEvaluatorRecoverySeconds, int>()
};
return AvroJsonSerializer<AvroYarnAppSubmissionParameters>.ToBytes(avroYarnAppSubmissionParameters);
}
示例2: ContextRuntime
/// <summary>
/// Create a new ContextRuntime.
/// </summary>
/// <param name="serviceInjector"></param>
/// <param name="contextConfiguration">the Configuration for this context.</param>
/// <param name="parentContext"></param>
public ContextRuntime(
IInjector serviceInjector,
IConfiguration contextConfiguration,
Optional<ContextRuntime> parentContext)
{
_serviceInjector = serviceInjector;
_injectedServices = Optional<ISet<object>>.Of(serviceInjector.GetNamedInstance<ServicesSet, ISet<object>>());
_contextInjector = serviceInjector.ForkInjector(contextConfiguration);
_contextLifeCycle = _contextInjector.GetInstance<ContextLifeCycle>();
_parentContext = parentContext;
_contextLifeCycle.Start();
}
示例3: RootContextLauncher
private RootContextLauncher(
IConfiguration contextConfiguration,
IConfiguration rootServiceConfig,
Optional<IConfiguration> rootTaskConfig,
IInjector injector)
{
_rootContextConfiguration = contextConfiguration;
_rootServiceInjector = injector.ForkInjector(rootServiceConfig);
Id = _rootServiceInjector
.ForkInjector(contextConfiguration)
.GetNamedInstance<ContextConfigurationOptions.ContextIdentifier, string>();
_services = _rootServiceInjector.GetNamedInstance<ServicesSet, ISet<object>>();
Logger.Log(Level.Verbose, string.Format(CultureInfo.InvariantCulture, "injected service(s)"));
RootTaskConfig = rootTaskConfig;
}
示例4: ContextRuntime
/// <summary>
/// Create a new ContextRuntime.
/// </summary>
/// <param name="serviceInjector"></param>
/// <param name="contextConfiguration">the Configuration for this context.</param>
/// <param name="parentContext"></param>
public ContextRuntime(
IInjector serviceInjector,
IConfiguration contextConfiguration,
Optional<ContextRuntime> parentContext)
{
_serviceInjector = serviceInjector;
// Note that for Service objects and handlers, we are not merging them into a separate
// class (e.g. ServiceContainer) due to the inability to allow service stacking if an instance
// of such a class were to be materialized. i.e. if a ServiceContainer object were initialized
// and a child ServiceConfiguration is submitted, when the child service injector tries to
// get the relevant handlers and services set, it will get the same set of handlers as
// previously instantiated by the parent injector, and thus will not allow the stacking
// of ServiceConfigurations.
_injectedServices = serviceInjector.GetNamedInstance<ServicesSet, ISet<object>>();
_serviceContextStartHandlers =
serviceInjector.GetNamedInstance<ContextConfigurationOptions.StartHandlers, ISet<IObserver<IContextStart>>>();
_serviceContextStopHandlers =
serviceInjector.GetNamedInstance<ContextConfigurationOptions.StopHandlers, ISet<IObserver<IContextStop>>>();
_serviceTaskStartHandlers =
serviceInjector.GetNamedInstance<TaskConfigurationOptions.StartHandlers, ISet<IObserver<ITaskStart>>>();
_serviceTaskStopHandlers =
serviceInjector.GetNamedInstance<TaskConfigurationOptions.StopHandlers, ISet<IObserver<ITaskStop>>>();
_contextInjector = serviceInjector.ForkInjector(contextConfiguration);
_contextLifeCycle = _contextInjector.GetInstance<ContextLifeCycle>();
_parentContext = parentContext;
try
{
_contextLifeCycle.Start();
}
catch (Exception e)
{
const string message = "Encountered Exception in ContextStartHandler.";
if (ParentContext.IsPresent())
{
throw new ContextStartHandlerException(
Id, Optional<string>.Of(ParentContext.Value.Id), message, e);
}
throw new ContextStartHandlerException(Id, Optional<string>.Empty(), message, e);
}
}
示例5: GetDeprecatedTaskRuntime
private TaskRuntime GetDeprecatedTaskRuntime(
IInjector taskInjector, string contextId, IConfiguration taskConfiguration, IHeartBeatManager heartBeatManager)
{
var taskId = string.Empty;
try
{
taskId = taskInjector.GetNamedInstance<TaskConfigurationOptions.Identifier, string>();
}
catch (Exception e)
{
var ex = new TaskClientCodeException(string.Empty, Id, "Unable to instantiate the new task", e);
Utilities.Diagnostics.Exceptions.CaughtAndThrow(ex, Level.Error, "Cannot get instance of Task ID: " + e.StackTrace, LOGGER);
}
LOGGER.Log(Level.Info, "Trying to inject task with configuration" + taskConfiguration);
return new TaskRuntime(taskInjector, contextId, taskId, heartBeatManager);
}