In web forms I would use constructor dependency injection in my models like the below:
[SitecoreType(AutoMap = true)]
public class Article
{
private readonly ICommonService _commonService;
public Article(ICommonService commonService)
{
_commonService = commonService;
}
[SitecoreId]
private Guid Id { get; set; }
public string Title { get; set; }
[SitecoreIgnore]
public string GetTestString
{
get { return _commonService.GetTestString(); }
}
}
The idea here is to move the logic into services and keep loosely coupled with DI. So Glass provides raw Sitecore data then the services help manipulate that data or pull in extra data to complete the model.
Is it possible to have a view rendering with a reference to the model which resolves the DI and the model is ready to use?: @inherits Glass.Mapper.Sc.Web.Mvc.GlassView
Currently when i attempt this I get No parameterless constructor defined for this object
I can get the above working by using a controller and passing the dependency into the model via the controller.
Is it possible to have this work in a simple view rendering to cut out the creation of a controller view for models that requires logic in addition to simple Glass ORM data?
Currently posted in Glass Mapper Google Group: https://groups.google.com/forum/#!topic/glasssitecoremapper/BJnfQGXR7S8