I was wondering is there\'s any side effect to registering the container within itself
IContainer container;
ContainerBuilder builder = new ContainerBuilder
Since you need to provide an instance of the container to builder.RegisterInstance(), you need to initialize it BEFORE passing it as an argument, which you are currently not doing. However, if you structure your container builder to build AFTER registration (and container initialization), you can successfully resolve the container instance in your class.
Please note that this is most certainly a design smell in Dependency Injection and you absolutely should not do this. Your container/kernel should only exist at the top level of your object graph. If you begin injecting your container, you're almost certainly on your way to a Service Locator Anti-Pattern.
void Main()
{
IContainer container = new ContainerBuilder().Build();
ContainerBuilder builder = new ContainerBuilder();
builder.RegisterInstance(container).As();
builder.RegisterType().As()
.WithParameter(new ResolvedParameter(
(pi, ctx) => pi.ParameterType == typeof(IContainer) && pi.Name == "Container",
(pi, ctx) => container
));
container = builder.Build();
var instance = container.Resolve();
}
public class ManagementServiceImp : IManagmentServiceImp
{
private IContainer _container;
public ManagementServiceImp(IContainer Container)
{
_container = Container;
_container.Dump();
}
}
public interface IManagmentServiceImp { }