本文整理汇总了C#中IInjector.GetInstance方法的典型用法代码示例。如果您正苦于以下问题:C# IInjector.GetInstance方法的具体用法?C# IInjector.GetInstance怎么用?C# IInjector.GetInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IInjector
的用法示例。
在下文中一共展示了IInjector.GetInstance方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: before
public void before()
{
context = new Context();
injector = context.injector;
injector.Map<IDirectCommandMap>().ToType<DirectCommandMap>();
subject = injector.GetInstance<IDirectCommandMap>() as DirectCommandMap;
}
示例2: MediatorFactory
/*============================================================================*/
/* Constructor */
/*============================================================================*/
public MediatorFactory (IInjector injector)
{
_injector = injector;
_manager = injector.HasMapping (typeof(IMediatorManager))
? injector.GetInstance (typeof(IMediatorManager)) as IMediatorManager
: new MediatorManager ();
_manager.ViewRemoved += RemoveMediators;
}
示例3: 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;
_contextInjector = serviceInjector.ForkInjector(contextConfiguration);
_contextLifeCycle = _contextInjector.GetInstance<ContextLifeCycle>();
_parentContext = parentContext;
_contextLifeCycle.Start();
}
示例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;
_injectedServices = Optional<ISet<object>>.Of(serviceInjector.GetNamedInstance<ServicesSet, ISet<object>>());
_contextInjector = serviceInjector.ForkInjector(contextConfiguration);
_contextLifeCycle = _contextInjector.GetInstance<ContextLifeCycle>();
_parentContext = parentContext;
_contextLifeCycle.Start();
}
示例5: Process
/*============================================================================*/
/* Public Functions */
/*============================================================================*/
public void Process(Object view, Type type, IInjector injector)
{
foreach (String fieldName in _fieldTypesByName.Keys)
{
FieldInfo field = view.GetType().GetField(fieldName);
if (field != null)
{
object valueToInject = injector.GetInstance(_fieldTypesByName[fieldName]);
if (valueToInject != null)
{
field.SetValue(view, valueToInject);
}
}
}
}
示例6: 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);
}
}