INNER CODE UNIT · C#

GetService

MvvmCross/MvvmCross · MvvmCross.Tests/MvxIoCSupportingTest.cs:128

        public object? GetService(Type serviceType) => _host.Services.GetService(serviceType);

        /// <summary>Registers a singleton instance.</summary>
        public void RegisterSingleton<TInterface>(TInterface instance)
            where TInterface : class
        {
            _host.InvalidateServiceProvider();
            _host.ServiceCollection.AddSingleton(instance);
        }

        /// <summary>Registers a singleton factory.</summary>
        public void RegisterSingleton<TInterface>(Func<TInterface> factory)
            where TInterface : class
        {
            _host.InvalidateServiceProvider();
            _host.ServiceCollection.AddSingleton<TInterface>(_ => factory());
        }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…