-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
The following code example (I'm targetting .net 8.0 FYI) compiles but at runtime the variable bar is null.
public interface IFoo {}
public class Foo : IFoo { }
public interface IBar { }
public class Bar : IBar { }
[Test]
public void TestUseMicrosoftDiAndLightInjectSideBySide()
{
// var builder = Host.CreateApplicationBuilder();
var services = new ServiceCollection();
services.AddSingleton<IFoo, Foo>();
var containerOptions = new ContainerOptions().WithMicrosoftSettings();
var container = new ServiceContainer(containerOptions);
container.Register<IBar, Bar>();
// "Bridge" LightInject and Microsoft DI
var serviceProvider = services.CreateLightInjectServiceProvider();
var foo = serviceProvider.GetService<IFoo>();
var bar = serviceProvider.GetService<IBar>();
Assert.That(foo, Is.Not.Null);
Assert.That(bar, Is.Not.Null);
}Is this by design?
My understanding is the point having this integration is so that you can register types with either Microsoft DI or LightInject and it just works because CreateLightInjectServiceProvider() ties the LightInjectContainer inside the Microsoft one?
Metadata
Metadata
Assignees
Labels
No labels