本文整理汇总了C#中IInjector类的典型用法代码示例。如果您正苦于以下问题:C# IInjector类的具体用法?C# IInjector怎么用?C# IInjector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IInjector类属于命名空间,在下文中一共展示了IInjector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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)
{
ContextConfiguration config = contextConfiguration as ContextConfiguration;
if (config == null)
{
var e = new ArgumentException("contextConfiguration is not of type ContextConfiguration");
Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
}
_contextLifeCycle = new ContextLifeCycle(config.Id);
_serviceInjector = serviceInjector;
_parentContext = parentContext;
try
{
_contextInjector = serviceInjector.ForkInjector();
}
catch (Exception e)
{
Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
Optional<string> parentId = ParentContext.IsPresent() ?
Optional<string>.Of(ParentContext.Value.Id) :
Optional<string>.Empty();
ContextClientCodeException ex = new ContextClientCodeException(ContextClientCodeException.GetId(contextConfiguration), parentId, "Unable to spawn context", e);
Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
}
// Trigger the context start events on contextInjector.
_contextLifeCycle.Start();
}
示例2: GroupCommClient
public GroupCommClient(
[Parameter(typeof(GroupCommConfigurationOptions.SerializedGroupConfigs))] ISet<string> groupConfigs,
[Parameter(typeof(TaskConfigurationOptions.Identifier))] string taskId,
StreamingNetworkService<GeneralGroupCommunicationMessage> networkService,
AvroConfigurationSerializer configSerializer,
IInjector injector)
{
_commGroups = new Dictionary<string, ICommunicationGroupClientInternal>();
_networkService = networkService;
foreach (string serializedGroupConfig in groupConfigs)
{
IConfiguration groupConfig = configSerializer.FromString(serializedGroupConfig);
IInjector groupInjector = injector.ForkInjector(groupConfig);
var commGroupClient = (ICommunicationGroupClientInternal)groupInjector.GetInstance<ICommunicationGroupClient>();
_commGroups[commGroupClient.GroupName] = commGroupClient;
}
networkService.Register(new StringIdentifier(taskId));
foreach (var group in _commGroups.Values)
{
group.WaitingForRegistration();
}
}
示例3: Approve
public static bool Approve(IInjector injector, IEnumerable<object> guards)
{
object guardInstance;
foreach (object guard in guards)
{
if (guard is Func<bool>)
{
if ((guard as Func<bool>)())
continue;
return false;
}
if (guard is Type)
{
if (injector != null)
guardInstance = injector.InstantiateUnmapped(guard as Type);
else
guardInstance = Activator.CreateInstance(guard as Type);
}
else
guardInstance = guard;
MethodInfo approveMethod = guardInstance.GetType().GetMethod("Approve");
if (approveMethod != null)
{
if ((bool)approveMethod.Invoke (guardInstance, null) == false)
return false;
}
else
{
throw(new Exception (String.Format("Guard {0} is not a valid guard. It doesn't have the method 'Approve'", guardInstance)));
}
}
return true;
}
示例4: EvaluatorSettings
private EvaluatorSettings(
[Parameter(typeof(ApplicationIdentifier))] string applicationId,
[Parameter(typeof(EvaluatorIdentifier))] string evaluatorId,
[Parameter(typeof(EvaluatorHeartbeatPeriodInMs))] int heartbeatPeriodInMs,
[Parameter(typeof(HeartbeatMaxRetry))] int maxHeartbeatRetries,
[Parameter(typeof(RootContextConfiguration))] string rootContextConfigString,
RuntimeClock clock,
IRemoteManagerFactory remoteManagerFactory,
REEFMessageCodec reefMessageCodec,
IInjector injector)
{
_injector = injector;
_applicationId = applicationId;
_evaluatorId = evaluatorId;
_heartBeatPeriodInMs = heartbeatPeriodInMs;
_maxHeartbeatRetries = maxHeartbeatRetries;
_clock = clock;
if (string.IsNullOrWhiteSpace(rootContextConfigString))
{
Utilities.Diagnostics.Exceptions.Throw(
new ArgumentException("empty or null rootContextConfigString"), Logger);
}
_rootContextConfig = new ContextConfiguration(rootContextConfigString);
_rootTaskConfiguration = CreateTaskConfiguration();
_rootServiceConfiguration = CreateRootServiceConfiguration();
_remoteManager = remoteManagerFactory.GetInstance(reefMessageCodec);
_operationState = EvaluatorOperationState.OPERATIONAL;
}
示例5: ModuleConnector
/*============================================================================*/
/* Constructor */
/*============================================================================*/
/**
* @private
*/
public ModuleConnector(IContext context)
{
IInjector injector= context.injector;
_rootInjector = GetRootInjector(injector);
_localDispatcher = injector.GetInstance(typeof(IEventDispatcher)) as IEventDispatcher;
context.WhenDestroying(Destroy);
}
示例6: ContextRuntime
public ContextRuntime(
string id,
IInjector serviceInjector,
IConfiguration contextConfiguration)
{
// This should only be used at the root context to support backward compatibility.
LOGGER.Log(Level.Info, "Instantiating root context");
_contextLifeCycle = new ContextLifeCycle(id);
_serviceInjector = serviceInjector;
_parentContext = Optional<ContextRuntime>.Empty();
try
{
_contextInjector = serviceInjector.ForkInjector();
}
catch (Exception e)
{
Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
Optional<string> parentId = ParentContext.IsPresent() ?
Optional<string>.Of(ParentContext.Value.Id) :
Optional<string>.Empty();
ContextClientCodeException ex = new ContextClientCodeException(ContextClientCodeException.GetId(contextConfiguration), parentId, "Unable to spawn context", e);
Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
}
// Trigger the context start events on contextInjector.
_contextLifeCycle.Start();
}
示例7: Apply
public static void Apply(IInjector injector, IEnumerable<object> hooks)
{
object hookInstance;
foreach (object hook in hooks)
{
if (hook is Action)
{
(hook as Action)();
continue;
}
if (hook is Type)
{
if (injector != null)
hookInstance = injector.InstantiateUnmapped(hook as Type);
else
hookInstance = Activator.CreateInstance(hook as Type);
}
else
hookInstance = hook;
MethodInfo hookMethod = hookInstance.GetType().GetMethod("Hook");
if (hookMethod != null)
hookMethod.Invoke (hookInstance, null);
else
throw new Exception ("Invalid hook to apply");
}
}
示例8: Process
/*============================================================================*/
/* Public Functions */
/*============================================================================*/
public void Process(object view, Type type, IInjector injector)
{
if(!_injectedObjects.ContainsKey(view))
{
InjectAndRemember(view, injector);
}
}
示例9: CommandMap
//---------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------
/**
* Creates a new <code>CommandMap</code> object
*
* @param eventDispatcher The <code>IEventDispatcher</code> to listen to
* @param injector An <code>IInjector</code> to use for this context
* @param reflector An <code>IReflector</code> to use for this context
*/
public CommandMap( IEventDispatcher eventDispatcher, IInjector injector, IReflector reflector )
{
this.eventDispatcher = eventDispatcher;
this.injector = injector;
this.reflector = reflector;
this.eventTypeMap = new Dictionary<string,Dictionary<Type, Dictionary<Type, Action<Event>>>>();
this.verifiedCommandClasses = new Dictionary<Type,bool>();
}
示例10: EventCommandTrigger
/*============================================================================*/
/* Constructor */
/*============================================================================*/
public EventCommandTrigger (IInjector injector, IEventDispatcher dispatcher, Enum type, Type eventClass = null, IEnumerable<CommandMappingList.Processor> processors = null, ILogger logger = null)
{
_dispatcher = dispatcher;
_type = type;
_eventClass = eventClass;
_mappings = new CommandMappingList(this, processors, logger);
_executor = new CommandExecutor(injector, _mappings.RemoveMapping);
}
示例11: ViewMap
//---------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------
/**
* Creates a new <code>ViewMap</code> object
*
* @param contextView The root view node of the context. The map will listen for ADDED_TO_STAGE events on this node
* @param injector An <code>IInjector</code> to use for this context
*/
public ViewMap( FrameworkElement contextView, IInjector injector )
: base(contextView, injector)
{
// mappings - if you can do it with fewer dictionaries you get a prize
this.mappedPackages = new List<string>();
this.mappedTypes = new Dictionary<Type,Type>();
this.injectedViews = new Dictionary<FrameworkElement,bool>(); //Warning was marked as weak
}
示例12: Unprocess
public void Unprocess(object view, Type type, IInjector injector)
{
if (_createdMediatorsByView.ContainsKey(view))
{
DestroyMediator(_createdMediatorsByView[view]);
_createdMediatorsByView.Remove(view);
}
}
示例13: Setup
public void Setup()
{
injector = new RobotlegsInjector();
viewInjector = new ViewInjectionProcessor();
injectionValue = MapSpriteForInjection();
view = new ViewWithInjection();
}
示例14: Setup
public void Setup()
{
injector = new robotlegs.bender.framework.impl.RobotlegsInjector();
viewProcessorFactory = new ViewProcessorFactory(injector);
trackingProcessor = new TrackingProcessor();
view = new object();
}
示例15: before
public void before()
{
context = new Context();
injector = context.injector;
injector.Map<IDirectCommandMap>().ToType<DirectCommandMap>();
subject = injector.GetInstance<IDirectCommandMap>() as DirectCommandMap;
}