コード例 #1
0
 public Subject(string argument1, TransientService service1, string argument2, SingletonService service2)
 {
     Argument1 = argument1;
     Service1  = service1;
     Argument2 = argument2;
     Service2  = service2;
 }
コード例 #2
0
 public LifeTimeController(TransientService transientService,
                           ScopedService scopedService, SingletonService singletonService)
 {
     _transientService = transientService;
     _scopedService    = scopedService;
     _singletonService = singletonService;
 }
コード例 #3
0
 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()}");
 }
コード例 #5
0
ファイル: ServiceHostTest.cs プロジェクト: weeble/mono
        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();
                }
            }
        }
コード例 #6
0
            public void DoIt()
            {
                SingletonService.ResolveTransient();

                TransientInstances.Add(
                    ServiceProvider.GetRequiredService <MyEmptyTransientService>()
                    );
            }
コード例 #7
0
        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);
        }
コード例 #8
0
    void OnDisable()
    {
        hpv_node_delegates.Clear();

        StopCoroutine(HPV_update_loop);
        SingletonService <HPV_Manager> .UnregisterSingletonInstance(this);

        HPV_Unity_Bridge.OnStop();
    }
コード例 #9
0
 public IlfracombeContext(
     DbContextOptions <IlfracombeContext> options,
     SingletonService singletonService,
     TransientService transientService)
     : base(options)
 {
     SingletonService = singletonService;
     TransientService = transientService;
 }
コード例 #10
0
        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;
        }
コード例 #11
0
        public void ReturnSameInstance()
        {
            //Given
            var sObj1 = SingletonService.GetInstance();
            var sObj2 = SingletonService.GetInstance();

            //When

            //Then
            Assert.Same(sObj1, sObj2);
        }
コード例 #12
0
 public CombeMartinContext(
     DbContextOptions <CombeMartinContext> options,
     SingletonService singletonService,
     ScopedService scopedService,
     TransientService transientService)
     : base(options)
 {
     SingletonService = singletonService;
     ScopedService    = scopedService;
     TransientService = transientService;
 }
コード例 #13
0
        // 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;
        }
コード例 #14
0
    /* 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!");
        }
    }
コード例 #15
0
    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);
    }
コード例 #16
0
        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);
        }
コード例 #17
0
        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;
        }
コード例 #18
0
ファイル: HPV_Node.cs プロジェクト: antoniohof/Holo_Toolset
    /* 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!");
        }
    }
コード例 #19
0
    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);
    }
コード例 #20
0
ファイル: HPV_Node.cs プロジェクト: antoniohof/Holo_Toolset
    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();
    }
コード例 #21
0
 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;
 }
コード例 #24
0
ファイル: ServiceHostTest.cs プロジェクト: Profit0004/mono
		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 ();
			}
		}
コード例 #25
0
 public Service(IInterface @interface, SingletonService singletonService)
 {
     this.@interface = @interface;
     this.singletonService = singletonService;
 }
コード例 #26
0
 public ScopedService(SingletonService singleton)
 {
     singleton.Add(this);
 }
コード例 #27
0
 void OnEnable()
 {
     SingletonService <HPV_Manager> .RegisterSingletonInstance(this);
 }
コード例 #28
0
 public Service(TransientService transientService, ScopedService scopedService, SingletonService singletonService)
 {
     this.transientService = transientService;
     this.scopedService    = scopedService;
     this.singletonService = singletonService;
 }
コード例 #29
0
 public SingletonUser(SingletonService singleton)
 {
 }
コード例 #30
0
 void OnEnable()
 {
     SingletonService <EventProcessor> .RegisterSingletonInstance(this);
 }
コード例 #31
0
 public CollectionServices(ScopeService scopeService, SingletonService singletonService, TransientService transientService)
 {
     _scopeService     = scopeService;
     _singletonService = singletonService;
     _transientService = transientService;
 }
コード例 #32
0
 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;
 }
コード例 #34
0
 void OnDisable()
 {
     SingletonService <EventProcessor> .UnregisterSingletonInstance(this);
 }