I’m trying to register types as self and as one interface.
When I add As<ICustomScreenDef>
I cannot access concrete types any more. However if I use AsImplementedInterfaces()
accessing concrete type works again.
Example:
public class ScreenDef : IScreenDef {}
public class MyScreen : ScreenDef, ICustomScreenDef {}
public class ScreenGroup
{
public ScreenGroup(MyScreen myScreen, IEnumerable<ICustomScreenDef> customScreenDefs){}
}
Program.cs:
builder.RegisterAssemblyTypes(screensAssembly).AssignableTo<IScreenDef>().
OnActivating(e => {
IScreenDef screenDef = ((IScreenDef)e.Instance);
screenDef.Init();
})
.OnActivated(
e => {
...
}
).AsSelf().As<ICustomScreenDef>().InstancePerDependency();
With this code ScreenGroup can’t be instantiated because myScreen is missing.
If I change
AsSelf().As<ICustomScreenDef>()
to AsSelf().AsImplementedInterfaces()
everything works. How can I make this work without using AsImplementedInterfaces()
?
I hope example captures potential problem since I simplified it.