public class MyApplication : Umbraco.Web.UmbracoApplication
the Application tag inside the global.asax file in the web root
public class MyTestSurfaceController : SurfaceController
but I get internal server error
In the global file I register the controllers:
var builder = new ContainerBuilder();
// register all controllers found in your assembly
builder.RegisterControllers(typeof(MvcApplication).Assembly);
builder.RegisterApiControllers(typeof(MvcApplication).Assembly);
// add custom class to the container as Transient instance
builder.RegisterType
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
but as soon as a call is added in the surfacecontroller to "public depinjController" it fails.
public class depinjController : SurfaceController
{
private readonly namespace.Utils.MyAwesomeContext _myAwesome;
public depinjController(namespace.Utils.MyAwesomeContext myAwesome)
{
_myAwesome = myAwesome;
}
[ChildActionOnly]
public ActionResult Index()
{
return Content("Hello World! Here is my id " + _myAwesome.MyId);
}
}
Dependency Injection - IOC
I was following the instructions at https://our.umbraco.com/documentation/reference/using-ioc but without success.
As per the instructions I have created:
but I get internal server error
In the global file I register the controllers: var builder = new ContainerBuilder(); // register all controllers found in your assembly builder.RegisterControllers(typeof(MvcApplication).Assembly); builder.RegisterApiControllers(typeof(MvcApplication).Assembly);
builder.RegisterControllers(typeof(Umbraco.Web.UmbracoApplication).Assembly); builder.RegisterApiControllers(typeof(Umbraco.Web.UmbracoApplication).Assembly);
// add custom class to the container as Transient instance builder.RegisterType
var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
but as soon as a call is added in the surfacecontroller to "public depinjController" it fails.
public class depinjController : SurfaceController { private readonly namespace.Utils.MyAwesomeContext _myAwesome;
I think you should register MyAwesomeContext in container too
is working on a reply...