Umbraco-CMS: LightInject Registering by convention is not possible as you have replaced the default AssemblyScanner.
I can’t register dependencies by convention.
container.RegisterAssembly() is completely unusable as the AssemblyScanner has been replaced with a NOP stub.
Line 61 Line 254
Umbraco version
I am seeing this issue on Umbraco version: 8.5.2
Reproduction
Specifics
Steps to reproduce
Spin up umbraco 8.5.2 site
Add the following to a c# file
public class Composer : IUserComposer
{
public void Compose(Composition composition)
{
var container = composition.Concrete as ServiceContainer;
Debug.Assert(container != null, nameof(container) + " != null");
container.RegisterAssembly(typeof(IFoo).Assembly);
// The following throws
container.GetInstance<IFoo>();
}
}
public interface IFoo
{
string Ping();
}
public class Foo : IFoo
{
public string Ping()
{
return "Pong";
}
}
Expected result
I expect to be able to resolve an instance implementing IFoo
Actual result
It doesn’t work.
However if I blast over the NOP scanner with the following it works as one would expect.
public void Compose(Composition composition)
{
var container = composition.Concrete as ServiceContainer;
Debug.Assert(container != null, nameof(container) + " != null");
// Replace NOP scanner
container.AssemblyScanner = new ServiceContainer().AssemblyScanner;
container.RegisterAssembly(typeof(IFoo).Assembly);
// The following does not throw
container.GetInstance<IFoo>();
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (14 by maintainers)
Interesting, so I could use Autofac/Lamar and pull the IContainer out in a UserComposer?
That could do with some documentation which I think is currently lacking, will see if I can find some time to have a go 😃
@Shazwazza @rustybox
I did some proof of concepts while contributing on the DI parts of Umbraco fall 2018.
Stuff might have changed, but the code can be looked at here:
https://github.com/lars-erik/our.umbraco.containers