public object Resolve() { var instance = Activator.CreateInstance(_target); Injector.Inject(instance); return(instance); }
public void ToValue(object value) { _injector.Inject(value); var resolver = new ValueResolver(value); AddResolver(resolver); }
public object Resolve() { if (_value != null) { return(_value); } _value = Activator.CreateInstance(_target); Injector.Inject(_value); return(_value); }
public void ExtraFieldShouldBeInjectedInCarrier() { var extra = new ExtraFieldPropagation.Extra(); extra.Put(Key1, Key1Value); var context = new SpanState(_context, new List <object> { extra }); Injector.Inject(context, _carrier); Assert.True(_carrier.Contains(new KeyValuePair <string, string>(Key1, Key1Value))); }
public static void Execute() { foreach (string tmpName in dicInject.Keys) { IInjector owner = dicInject[tmpName]; List <ITemplate> tmpList = dicTemplates[tmpName]; IInputValue inputVO = dicInput[tmpName]; IInitValue initVO = dicInit[tmpName]; FileSettingText setting = dicSetting[tmpName]; owner.Init(initVO); owner.Inject(inputVO, tmpList); foreach (ITemplate iTemp in tmpList) { string FileName = iTemp.GetType().ToString(); string writeContent = iTemp.TransformText(); string directoryPath = setting.SaveTo; string filePath = directoryPath + FileName; if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } File.WriteAllText(filePath, writeContent); } } }
protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { using (var clientTrace = new ClientTrace(_serviceName, _getClientTraceRpc(request))) { if (clientTrace.Trace != null) { _injector.Inject(clientTrace.Trace.CurrentSpan, request.Headers); } var result = await clientTrace.TracedActionAsync(base.SendAsync(request, cancellationToken)).ConfigureAwait(false); if (clientTrace.Trace != null) { clientTrace.AddAnnotation(Annotations.Tag(zipkinCoreConstants.HTTP_PATH, result.RequestMessage.RequestUri.LocalPath)); clientTrace.AddAnnotation(Annotations.Tag(zipkinCoreConstants.HTTP_METHOD, result.RequestMessage.Method.Method)); if (_logHttpHost) { clientTrace.AddAnnotation(Annotations.Tag(zipkinCoreConstants.HTTP_HOST, result.RequestMessage.RequestUri.Host)); } if (!result.IsSuccessStatusCode) { clientTrace.AddAnnotation(Annotations.Tag(zipkinCoreConstants.HTTP_STATUS_CODE, ((int)result.StatusCode).ToString())); } } return(result); } }
private void ResolveDependencies(ICoreCommand command) { if (_injector != null) { _injector.Inject(command, InjectionMode.ResolveOnly); } }
private Command CreateCommand(Type type) { var constructor = type.GetConstructor(Type.EmptyTypes); var command = constructor?.Invoke(new object[] { }); return((Command)binder.Inject(command, parameters)); }
private void InjectedWorker_DoWork(object sender, DoWorkEventArgs e) { if (InvokeRequired) { Invoke(new InjectedWorker_DoWork_Delegate(InjectedWorker_DoWork), sender, e); } else { injected = curInjector.Inject(proc, FileToInject); if (injected != IntPtr.Zero) { txtInjLog.Text += Path.GetFileName(FileToInject) + " succesfully injected into process: 0x" + (proc.Is64bit ? injected.ToInt64().ToString("X16") : injected.ToInt32().ToString("X8")) + Environment.NewLine; log.Log(LogType.Success, "{0} succesfully injected into {1} (0x{2})", Path.GetFileName(FileToInject), proc.FileName, proc.Is64bit ? injected.ToInt64().ToString("X16") : injected.ToInt32().ToString("X8")); btnExport.Enabled = hasExports; btnInject.Enabled = false; } else { txtInjLog.Text += "Failed to inject module into process (See log for details!)" + Environment.NewLine; log.Log(LogType.Error, "Injection failed: {0}", Marshal.GetLastWin32Error().ToString("X")); } } }
public object SpawnInstance(IObjectResolver resolver) { Component component; var parent = destination.GetParent(); if (destination.Prefab != null) { if (destination.Prefab.gameObject.activeSelf) { destination.Prefab.gameObject.SetActive(false); } component = UnityEngine.Object.Instantiate(destination.Prefab, parent); } else { var name = string.IsNullOrEmpty(destination.NewGameObjectName) ? ImplementationType.Name : destination.NewGameObjectName; var gameObject = new GameObject(name); gameObject.SetActive(false); if (parent != null) { gameObject.transform.SetParent(parent); } component = gameObject.AddComponent(ImplementationType); } injector.Inject(component, resolver, Parameters); component.gameObject.SetActive(true); return(component); }
public object Resolve() { var result = _factory(); Injector.Inject(result); return(result); }
private State CreateStateInstance(Type type) { State state = Activator.CreateInstance(type) as State; _injector.Inject(state); return(state); }
private void Awake() { _injector = new Injector(); _directCommand = new DirectCommand(_injector); _eventDispatcher = new EventDispatcher(); _eventCommandMap = new EventCommandMap(_eventDispatcher, _injector); _viewFactory = new ViewFactory(); _mediatorMap = new MediatorMap(_viewFactory, _injector); _entityDatabase = new EntityDatabase(); _systemMap = new SystemMap(_entityDatabase); _updater = new Updater(); _injector.Inject(_directCommand); _injector.Inject(_eventDispatcher); _injector.Inject(_entityDatabase); _injector.Inject(_mediatorMap); _injector.Inject <IUpdater>(_updater); // systems _systemMap.Add(new PlayerMovementSystem()); _systemMap.Add(new PlayerShootingSystem()); _systemMap.Add(new CameraFollowSystem()); _systemMap.Add(new EnemySpawnerSystem()); _systemMap.Add(new EnemyMovementSystem()); _systemMap.Add(new EnemyDamageSystem()); _systemMap.Add(new EnemyAttackSystem()); _systemMap.Add(new PlayerDamageSystem()); _systemMap.Add(new EnemySinkingSystem()); // injection _injector.Inject <IGameData>(gameData); _injector.Inject(new AudioModel()); _injector.Inject(new PlayerHealthModel()); _injector.Inject(new ScoreModel()); // view factory _viewFactory.Register(damageView, false); _viewFactory.Register(gameOverView, false); _viewFactory.Register(healthView, false); _viewFactory.Register(pauseView, false); _viewFactory.Register(scoreView, false); // mediator _mediatorMap.Map <DamageMediator>(ViewType.Damage); _mediatorMap.Map <GameOverMediator>(ViewType.GameOver); _mediatorMap.Map <HealthMediator>(ViewType.Health); _mediatorMap.Map <PauseMediator>(ViewType.Pause); _mediatorMap.Map <ScoreMediator>(ViewType.Score); // event command _eventCommandMap.Map(GameEvent.GameOverComplete, new RestartCommand()); }
public void Map(ICommand command) { _commands.Add(command); if (_injector != null) { _injector.Inject(command, InjectionMode.ResolveOnly); } }
public void HttpRequest(HttpRequestMessage request) { clientTrace = new ClientTrace(this._serviceName, request.Method.Method); if (clientTrace.Trace != null) { _injector.Inject(clientTrace.Trace.CurrentSpan, request.Headers); } }
public void DoWork(IFileExtractor extractor, IClimbExtractor climbExtractor, IInjector injector) { foreach (var fileName in extractor.ExtractFilePaths()) { var climbs = GetClimbs(extractor, climbExtractor, fileName); injector.Inject(climbs, fileName); } }
public object SpawnInstance(IObjectResolver resolver) { if (specificInstance != null) { injector.Inject(specificInstance, resolver, parameters); return(specificInstance); } return(injector.CreateInstance(resolver, parameters)); }
void IDirectCommand.Execute(ICommand command) { if (_injector != null) { _injector.Inject(command, InjectionMode.ResolveOnly); } command.Execute(); }
public void Inject <TCarrier>(ISpanContext spanContext, IFormat <TCarrier> format, TCarrier carrier) { VerifySupportedFormat(format); ITextMap implCarrier = GetRealCarrier(carrier); Trace trace = GetRealSpanContext(spanContext).Trace; _injector.Inject(trace.CurrentSpan, implCarrier); }
public Context() { Injector = new Injector(); Injector.Bind <IInjector>().ToValue(Injector); Injector.Bind <IContext>().ToValue(this); _configManager = new ConfigManager(); Injector.Inject(_configManager); }
public void Inject <TCarrier>(ISpanContext spanContext, IFormat <TCarrier> format, TCarrier carrier) { IInjector injector = Registry.GetInjector(format); if (injector == null) { throw new NotSupportedException($"Unsupported format '{format}'"); } injector.Inject((SpanContext)spanContext, carrier); }
Component FindComponent(IObjectResolver resolver) { Component component = null; var parent = destination.GetParent(); if (parent != null) { component = parent.GetComponentInChildren(ImplementationType); if (component == null) { throw new VContainerException(ImplementationType, $"Component {ImplementationType} is not in the parent {parent.name}"); } } else if (destination.Scene.IsValid()) { var gameObjectBuffer = UnityEngineObjectListBuffer <GameObject> .Get(); destination.Scene.GetRootGameObjects(gameObjectBuffer); foreach (var gameObject in gameObjectBuffer) { component = gameObject.GetComponentInChildren(ImplementationType, true); if (component != null) { break; } } if (component == null) { throw new VContainerException(ImplementationType, $"Component {ImplementationType} is not in this scene {destination.Scene.path}"); } } else { throw new VContainerException(ImplementationType, "Invalid Component find target"); } if (component is MonoBehaviour monoBehaviour) { injector.Inject(monoBehaviour, resolver, Parameters); } return(component); }
protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { using (var clientTrace = new ClientTrace(_serviceName, request.Method.ToString())) { if (clientTrace.Trace != null) { _injector.Inject(clientTrace.Trace.CurrentSpan, request.Headers); } return(await clientTrace.TracedActionAsync(base.SendAsync(request, cancellationToken))); } }
public object Resolve(IInjector injector, Type type) { var targetType = _value; var result = CreateInstance(injector, targetType); if (result != null) { injector.Inject(result); } return(result); }
public static void Inject(this IInjector injector, object instance) { Assert.IsNotNull(instance); injector.Inject(new InjectionContext { Container = injector.Container, Instance = instance, DeclaringType = instance.GetType() }); }
public void Inject(SpanContext spanContext, object carrier) { try { _decorated.Inject(spanContext, carrier); } catch (Exception ex) { _logger.LogWarning(ex, "Error when injecting SpanContext into carrier. Handling gracefully."); } }
/// <summary> /// /// <para>On_FromClientToGateway_Received:</para> /// /// <para>Check <seealso cref="IBTracingServiceInterface.On_FromClientToGateway_Received"/> for detailed documentation</para> /// /// </summary> public void On_FromClientToGateway_Received(HttpListenerContext _Context, Action <string> _ErrorMessageAction = null) { var CreatedTrace = Trace.Create(); TraceInjector.Inject(CreatedTrace.CurrentSpan, _Context.Request.Headers); CommonHttpTraceAnnotations(CreatedTrace, _Context); CreatedTrace.Record(Annotations.ServerRecv()); CommonHttpTraceAnnotations(CreatedTrace, _Context); CreatedTrace.Record(Annotations.LocalOperationStart(ProgramUniqueID + "->" + _Context.Request.Url.AbsolutePath)); }
public void Map <T, TK>() where T : struct, IEvent where TK : ICommand <T> { var eventType = typeof(T); if (!_commandMap.TryGetValue(eventType, out var group)) { group = new CommandGroup <T>(); Injector.Inject(group); _commandMap.Add(eventType, group); } group.Add <TK>(); }
public void Tracer_ExtractAndInject_ShouldUseTheCorrectCodec() { var carrier = "carrier, yo"; var spanContext = Substitute.For <ILetsTraceSpanContext>(); _mockExtractor.Extract(Arg.Is <string>(c => c == carrier)); _mockInjector.Inject(Arg.Is <ISpanContext>(sc => sc == spanContext), Arg.Is <string>(c => c == carrier)); _builtTracer.Extract(_format, carrier); _builtTracer.Inject(spanContext, _format, carrier); _mockExtractor.Received(1).Extract(Arg.Any <string>()); _mockInjector.Received(1).Inject(Arg.Any <ISpanContext>(), Arg.Any <string>()); }
public bool Inject(IInjector injector) { if (injector.Injected(this)) { return(true); } Controller.Data.Trace_Current_Mod = this; var result = injector.Inject(this); Controller.Data.Trace_Current_Mod = null; return(result); }
public bool Inject( IInjector injector ) { if( injector.Injected( this ) ) { return true; } Controller.Data.Trace_Current_Mod = this; var result = injector.Inject( this ); Controller.Data.Trace_Current_Mod = null; return result; }