using Microsoft.Extensions.DependencyInjection; // create a request for a service with a specific interface var request = new ServiceRequest(typeof(IMyService)); // get an instance of the kernel var kernel = serviceProvider.GetService(); // use the kernel to create an instance of the requested service var myService = kernel.CreateRequest(request).Resolve();
using Grace.DependencyInjection; // create a request for a specific object var request = new TypeRequest(typeof(MyObject)); // create a new instance of the kernel var kernel = new DependencyInjectionContainer(); // use the kernel to create an instance of the requested object var myObject = kernel.CreateRequest(request).Activate();This example uses the Grace.DependencyInjection package to create a new request for an object of type MyObject. A new instance of the DependencyInjectionContainer class is created and used to instantiate the requested object. The resulting instance is returned in the form of the myObject variable. Package Library: - Microsoft.Extensions.DependencyInjection (for example 1) - Grace.DependencyInjection (for example 2)