public Subject(string argument1, TransientService service1, string argument2, SingletonService service2) { Argument1 = argument1; Service1 = service1; Argument2 = argument2; Service2 = service2; }
public LifeTimeController(TransientService transientService, ScopedService scopedService, SingletonService singletonService) { _transientService = transientService; _scopedService = scopedService; _singletonService = singletonService; }
public ValuesController(ScopedService scoped, TransientService transient, SingletonService singleton, ICorrelationContextAccessor accessor) { _accessor = accessor; _scoped = scoped; _transient = transient; _singleton = singleton; }
public WeatherForecastController(ILogger <WeatherForecastController> logger, IServiceProvider serviceProvider, SingletonService singletonService) { _logger = logger; Console.WriteLine($"Controller中注入的ServiceProvider:{serviceProvider.GetHashCode()}"); }
public void InstanceWithSingletonMode() { SingletonService instance = new SingletonService(); ServiceHost host = new ServiceHost(instance); Assert.IsNotNull(host.Description.Behaviors.Find <ServiceBehaviorAttribute> ().GetWellKnownSingleton(), "#1"); host.AddServiceEndpoint( typeof(SingletonService), new BasicHttpBinding(), new Uri("http://localhost:37564/s2")); // in case Open() didn't fail, we need to close the host. // And even if Close() caused the expected exception, // the test should still fail. try { host.Open(); ChannelDispatcher cd = (ChannelDispatcher)host.ChannelDispatchers [0]; DispatchRuntime dr = cd.Endpoints [0].DispatchRuntime; Assert.IsNotNull(dr.InstanceContextProvider, "#2"); InstanceContext ctx = dr.InstanceContextProvider.GetExistingInstanceContext(null, null); Assert.IsNotNull(ctx, "#3"); Assert.AreEqual(instance, ctx.GetServiceInstance(), "#4"); } finally { if (host.State == CommunicationState.Opened) { host.Close(); } } }
public void DoIt() { SingletonService.ResolveTransient(); TransientInstances.Add( ServiceProvider.GetRequiredService <MyEmptyTransientService>() ); }
public async Task InvokeAsync(HttpContext context, TransientService transientService, ScopedService scopedService, SingletonService singletonService) { context.Items.Add("CustomMiddlewareTransient", "Transient Middleware - " + transientService.GetGuid()); context.Items.Add("CustomMiddlewareScoped", "Scoped Middleware - " + scopedService.GetGuid()); context.Items.Add("CustomMiddlewareSingleton", "Singleton Middleware - " + singletonService.GetGuid()); await _next(context); }
void OnDisable() { hpv_node_delegates.Clear(); StopCoroutine(HPV_update_loop); SingletonService <HPV_Manager> .UnregisterSingletonInstance(this); HPV_Unity_Bridge.OnStop(); }
public IlfracombeContext( DbContextOptions <IlfracombeContext> options, SingletonService singletonService, TransientService transientService) : base(options) { SingletonService = singletonService; TransientService = transientService; }
public MyJob( TransientService transientService, // System.InvalidOperationException: Cannot consume scoped service 'Scope.Services.ScopeService' from singleton 'Microsoft.AspNetCore.Hosting.Internal.HostedServiceExecutor' // ScopeService scopeService, SingletonService singletonService) { this.transientService = transientService; // this.scopeService = scopeService; this.singletonService = singletonService; }
public void ReturnSameInstance() { //Given var sObj1 = SingletonService.GetInstance(); var sObj2 = SingletonService.GetInstance(); //When //Then Assert.Same(sObj1, sObj2); }
public CombeMartinContext( DbContextOptions <CombeMartinContext> options, SingletonService singletonService, ScopedService scopedService, TransientService transientService) : base(options) { SingletonService = singletonService; ScopedService = scopedService; TransientService = transientService; }
// private ITransientService transient; // private ScopedService scoped; public DummyController( // TransientService transient, // ScopedService scoped, SingletonService singleton, SingletonExService exsingleton ) { this.exsingleton = exsingleton; this.singleton = singleton; // this.transient = transient; // this.scoped = scoped; }
/* Startup the node, opens the file */ void Start() { m_event_processor = SingletonService <EventProcessor> .GetSingleton(); m_manager = SingletonService <HPV_Manager> .GetSingleton(); if (!m_event_processor) { Debug.LogError("Make sure there is exactly ONE EventProcessor.cs script in the scene."); return; } if (!m_manager) { Debug.LogError("Make sure there is exactly ONE HPV_Manager.cs script present in the scene."); return; } // init the player int node_id = m_manager.initPlayer(new HPVEventDelegate(onHPVEvent)); if (node_id >= 0) { m_node_id = (byte)node_id; //string filepath = Application.streamingAssetsPath + "/../../" + filename; string filepath = filename; int ret = m_manager.openVideo(m_node_id, filepath); if (ret == 1) { // store parameters of the file int fps = m_manager.getFrameRate(m_node_id); width = m_manager.getWidth(m_node_id); height = m_manager.getHeight(m_node_id); int number_of_frames = m_manager.getNumberOfFrames(m_node_id); hpv_type = m_manager.getCompressionType(m_node_id); /* If state == internal, video will play using internal clock. This call also sets loop mode to LOOP */ m_manager.setSyncState(m_node_id, HPV_Unity_Bridge.HPVSyncState.HPV_SYNC_INTERNAL); /* ... else, wait for external sync, using one of the seek methods */ //m_manager.setSyncState(m_node_id, HPV_Unity_Bridge.HPVSyncState.HPV_SYNC_EXTERNAL); //Debug.Log("Opened video " + filename + " with total of " + number_of_frames + " of frames and dimensions " + width + "x" + height + " @ " + fps + "fps [TYPE: " + HPV_Unity_Bridge.HPVCompressionTypeStrings[(int)hpv_type] + "]"); b_needs_init = true; } } else { Debug.LogError("Couldn't create new HPV_Video node!"); } }
public async Task <string> Singleton([FromServices] SingletonService service) { Console.WriteLine($"1. 注入服务Id: {service.Id}"); var innerService1 = _serviceProvider.GetService <SingletonService>(); Console.WriteLine($"2. 方法内获取的服务Id: {innerService1!.Id}"); var innerService2 = _serviceProvider.GetService <SingletonService>(); Console.WriteLine($"3. 方法内获取的服务Id: {innerService2!.Id}"); return(service.Id); }
public void CreateInstance_ExplicitParametersMixed_ReturnsInstance() { var service1 = new TransientService(); var service2 = new SingletonService(); var argument1 = "Hello"; var argument2 = "Hello"; var subject = ActivatorUtilities.CreateInstance <Subject>(ServiceProvider, service1, argument1, service2, argument2); Assert.NotNull(subject); Assert.Equal(service1, subject.Service1); Assert.Equal(service2, subject.Service2); Assert.Equal(argument1, subject.Argument1); Assert.Equal(argument2, subject.Argument2); }
public InjectionController(ScopedService scopedCounter1, ScopedService scopedCounter2, SingletonService singletonCounter1, SingletonService singletonCounter2, TransientService transientCounter1, TransientService transientCounter2) { _scopedCounter1 = scopedCounter1; _scopedCounter2 = scopedCounter2; _singletonCounter1 = singletonCounter1; _singletonCounter2 = singletonCounter2; _transientCounter1 = transientCounter1; _transientCounter2 = transientCounter2; }
/* Startup the node, opens the file */ void Start() { m_event_processor = SingletonService <EventProcessor> .GetSingleton(); m_manager = SingletonService <HPV_Manager> .GetSingleton(); if (!m_event_processor) { Debug.LogError("Make sure there is exactly ONE EventProcessor.cs script in the scene."); return; } if (!m_manager) { Debug.LogError("Make sure there is exactly ONE HPV_Manager.cs script present in the scene."); return; } // init the player int node_id = m_manager.initPlayer(new HPVEventDelegate(onHPVEvent)); if (node_id >= 0) { m_node_id = (byte)node_id; string filepath = Application.streamingAssetsPath + "/../../" + filename; int ret = m_manager.openVideo(m_node_id, filepath); if (ret == 1) { // store parameters of the file int fps = m_manager.getFrameRate(m_node_id); width = m_manager.getWidth(m_node_id); height = m_manager.getHeight(m_node_id); int number_of_frames = m_manager.getNumberOfFrames(m_node_id); hpv_type = m_manager.getCompressionType(m_node_id); ret = m_manager.startVideo(m_node_id); ret = m_manager.setLoopState(m_node_id, 1); Debug.Log("Opened video " + filename + " with total of " + number_of_frames + " of frames and dimensions " + width + "x" + height + " @ " + fps + "fps [TYPE: " + HPV_Unity_Bridge.HPVCompressionTypeStrings[(int)hpv_type] + "]"); b_needs_init = true; } } else { Debug.LogError("Couldn't create new HPV_Video node!"); } }
public static SingletonService GetInstance() { if (_Instance == null) { // obtain lock so no other threads can access it until the current thread is done lock (_lockObj) { // is it still null? another thread may have initialized _Instance before // the current thread obtained the lock if (_Instance == null) { _Instance = new SingletonService(); } } } return(_Instance); }
public override void OnInspectorGUI() { DrawDefaultInspector(); HPV_Manager manager = SingletonService <HPV_Manager> .GetSingleton(); if (!manager) { return; } byte m_node_id = ((HPV_Node)target).getID(); GUILayoutOption[] options = { GUILayout.Width(250), GUILayout.Height(100) }; // global vertical EditorGUILayout.BeginVertical(options); EditorGUILayout.Separator(); // play controls horizontal EditorGUILayout.LabelField("Play Controls"); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(playState_str, GUILayout.MinWidth(75), GUILayout.ExpandWidth(true), GUILayout.MinHeight(40), GUILayout.ExpandHeight(true))) { playState = !playState; if (playState) { playState_str = "Stop"; loop_in = 0; loop_out = manager.getNumberOfFrames(m_node_id); rangeMin = 0.0f; rangeMax = 1.0f; speed = 1.0f; prev_speed = 1.0f; seek = 0.0f; prev_seek = 0.0f; manager.startVideo(m_node_id); } else { playState_str = "Play"; manager.stopVideo(m_node_id); } } if (playState) { if (GUILayout.Button(pauzeState_str, GUILayout.MinWidth(75), GUILayout.ExpandWidth(true), GUILayout.MinHeight(40), GUILayout.ExpandHeight(true))) { pauzeState = !pauzeState; if (pauzeState) { pauzeState_str = "Resume"; manager.pauseVideo(m_node_id); } else { pauzeState_str = "Pauze"; manager.resumeVideo(m_node_id); } } } // end play controls horizontal EditorGUILayout.EndHorizontal(); // start pauze controls horizontal EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("<< BWD", GUILayout.MinWidth(75), GUILayout.ExpandWidth(true), GUILayout.MinHeight(40), GUILayout.ExpandHeight(true))) { manager.setDirection(m_node_id, false); } if (GUILayout.Button("FWD >>", GUILayout.MinWidth(75), GUILayout.ExpandWidth(true), GUILayout.MinHeight(40), GUILayout.ExpandHeight(true))) { manager.setDirection(m_node_id, true); } // end pauze controls horizontal EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Speed"); speed = EditorGUILayout.Slider(speed, -10, 10); if (!isNearlyEqual(speed, prev_speed)) { prev_speed = speed; manager.setSpeed(m_node_id, speed); } EditorGUILayout.Separator(); EditorGUILayout.LabelField("Loop"); loop_index = EditorGUILayout.Popup(loop_index, loop_options); if (loop_index != prev_loop_index) { manager.setLoopState(m_node_id, loop_index); prev_loop_index = loop_index; } EditorGUILayout.IntField(loop_in); EditorGUILayout.IntField(loop_out); EditorGUILayout.MinMaxSlider(ref rangeMin, ref rangeMax, 0.0f, 1.0f); if (GUILayout.Button("Update loop points")) { loop_in = (int)(rangeMin * (manager.getNumberOfFrames(m_node_id) - 1)); loop_out = (int)(rangeMax * (manager.getNumberOfFrames(m_node_id) - 1)); manager.setLoopIn(m_node_id, loop_in); manager.setLoopOut(m_node_id, loop_out); } EditorGUILayout.Separator(); EditorGUILayout.LabelField("Seek"); seek = EditorGUILayout.Slider(seek, 0.0f, 1.0f); if (!isNearlyEqual(seek, prev_seek)) { manager.seekToPos(m_node_id, seek); prev_seek = seek; } bShowStats = EditorGUILayout.Foldout(bShowStats, "Decode stats"); if (bShowStats) { if (bShowStats != prevShowStats) { manager.enableStats(m_node_id, bShowStats); prevShowStats = bShowStats; } IntPtr ptr = manager.getDecodeStatsPtr(m_node_id); HPV_Unity_Bridge.HPVDecodeStats decode_stats = (HPV_Unity_Bridge.HPVDecodeStats)Marshal.PtrToStructure(ptr, typeof(HPV_Unity_Bridge.HPVDecodeStats)); string stats = "HDD: " + (decode_stats.hdd_read_time / (float)1e6).ToString("F") + "ms"; stats += "\nL4Z: " + (decode_stats.l4z_decompress_time / (float)1e6).ToString("F") + "ms"; stats += "\nGPU: " + (decode_stats.gpu_upload_time / (float)1e6).ToString("F") + "ms"; EditorGUILayout.HelpBox(stats, MessageType.Info); Repaint(); } else if (!bShowStats && prevShowStats) { manager.enableStats(m_node_id, bShowStats); prevShowStats = bShowStats; } // end global vertical EditorGUILayout.EndVertical(); }
public ScopeRepo1(SingletonService singleton, ScopeService scope, TransientService transient) { this.singleton = singleton; this.scope = scope; this.transient = transient; }
public HandlerWithSingletonService(SingletonService service) { Service = service; }
public TypedClientWithSingletonService(HttpClient httpClient, SingletonService service) { HttpClient = httpClient; Service = service; }
public void InstanceWithSingletonMode () { var ep = NetworkHelpers.LocalEphemeralEndPoint().ToString(); SingletonService instance = new SingletonService (); ServiceHost host = new ServiceHost (instance); Assert.IsNotNull (host.Description.Behaviors.Find<ServiceBehaviorAttribute> ().GetWellKnownSingleton (), "#1"); host.AddServiceEndpoint ( typeof (SingletonService), new BasicHttpBinding (), new Uri ("http://" + ep + "/s2")); // in case Open() didn't fail, we need to close the host. // And even if Close() caused the expected exception, // the test should still fail. try { host.Open (); ChannelDispatcher cd = (ChannelDispatcher) host.ChannelDispatchers [0]; DispatchRuntime dr = cd.Endpoints [0].DispatchRuntime; Assert.IsNotNull (dr.InstanceContextProvider, "#2"); InstanceContext ctx = dr.InstanceContextProvider.GetExistingInstanceContext (null, null); Assert.IsNotNull (ctx, "#3"); Assert.AreEqual (instance, ctx.GetServiceInstance (), "#4"); } finally { if (host.State == CommunicationState.Opened) host.Close (); } }
public Service(IInterface @interface, SingletonService singletonService) { this.@interface = @interface; this.singletonService = singletonService; }
public ScopedService(SingletonService singleton) { singleton.Add(this); }
void OnEnable() { SingletonService <HPV_Manager> .RegisterSingletonInstance(this); }
public Service(TransientService transientService, ScopedService scopedService, SingletonService singletonService) { this.transientService = transientService; this.scopedService = scopedService; this.singletonService = singletonService; }
public SingletonUser(SingletonService singleton) { }
void OnEnable() { SingletonService <EventProcessor> .RegisterSingletonInstance(this); }
public CollectionServices(ScopeService scopeService, SingletonService singletonService, TransientService transientService) { _scopeService = scopeService; _singletonService = singletonService; _transientService = transientService; }
public ServiceClient2([TestContract("c2")] Service service, SingletonService singletonService) { this.service = service; this.singletonService = singletonService; }
public Handler2(Context testContext, SingletonService service) { this.testContext = testContext; this.service = service; }
void OnDisable() { SingletonService <EventProcessor> .UnregisterSingletonInstance(this); }