I’m trying to pass my Autofac’s container to a factory but it keeps returning null.

Program.cs:

var builder = new ContainerBuilder(); builder.RegisterType<MenuFactory>() .As<IFactory<Menu, Type>>() .WithParameter(new TypedParameter(typeof(IContainer), _container)) .SingleInstance(); _container = builder.Build(); 

MenuFactory.cs:

public MenuFactory(IContainer container) { _container = container; } 

Why isn’t this working? I’ve also tried this:

builder.RegisterType<MenuFactory>() .As<IFactory<Menu, Type>>() .WithParameter("container", _container) .SingleInstance(); 

submitted by /u/Asusralis
[link] [comments]

Leave a Reply