IOC using AutoFac for internal class

autofac, class, internal, inversion-of-control

Solution

Your options:

- Make `CommonSvc` public

- Annotate your assembly with an InternalsVisibleToAttribute to make internal types visible to the calling assembly.

- Instead of registering `CommonSvc` directly, use `RegisterAssemblyTypes()` to register it by convention. For example:

    builder.RegisterAssemblyTypes(typeof(SomeOtherTypeInTheSameAssembly).Assembly)
           .Where(t => typeof(SomeInterface).IsAssignableFrom(t))
           .AsImplementedInterfaces();

Problem

I have an internal class which is internal visible to a service Factory. It is also inheriting an public interface. When I want to use its functionality in my application, I am declaring object for the interface and getting it instantiated for the particular class through service factory. Now we are using MVC and I want to create IOC for this class in my one of the controller. This class being internal, I can not register this in global.ascx For example when I am writing builder.RegisterType().As().InstancePerHttpRequest() ; The CommonSvc being internal, it is throwing compile time error as Services.CommonSvc' is inaccessible due to its protection level Please advise

Original source