Hi,
I’m trying to get SimpleInjector to work with a SurfaceController but get the following error:
Exception message: No parameterless constructor defined for this object.
I currently using
- Umbraco 7.2.3
- SimpleInjector.Integration.Web.Mvc 3.0.5
- In an external project I have Entity Framework 6
This is my setup
public class Startup : Umbraco.Web.UmbracoApplication
{
protected override void OnApplicationStarted(object sender, EventArgs e)
{
base.OnApplicationStarted(sender, e);
// Create the container as usual.
var container = new Container();
container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();
// Register your types, for instance:
//Does not help issue: container.Register(()=> UmbracoContext.Current, Lifestyle.Singleton);
container.Register<IDataContext, PortalDataContext>(Lifestyle.Singleton);
// This is an extension method from the integration package.
container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
// This is an extension method from the integration package as well.
container.RegisterMvcIntegratedFilterProvider();
container.Verify();
DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
}
}
And here’s my class trying to use it
public class RegisterFormSurfaceController : SurfaceController
{
public RegisterFormSurfaceController(IDataContext dataContext)
{
_dataContext = dataContext;
}
private IDataContext _dataContext { get; }
public ActionResult GetRegister()
{
var model = new RegisterFormViewModel();
var optionsMobile =
(from c in _dataContext.Countries
select new OptionModel
{
Id = c.CountryID,
Value = $"{c.CountryName} ({c.DialCode})"
}).ToList();
model.MobileNumberPrefixOptions = optionsMobile;
return PartialView("~/Views/Partials/RegisterForm.cshtml", model);
}
I’ve tried various options with no joy, any help is appreciated.
Kind regards and many thanks
Si
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/71596-umbraco-723-dependency-injection-with-simpleinjector