Skip to content

Instantly share code, notes, and snippets.

@takahirohonda
Created September 25, 2019 13:11
Show Gist options
  • Save takahirohonda/d7be623b24408f8d5cad47e5fbeda492 to your computer and use it in GitHub Desktop.
Save takahirohonda/d7be623b24408f8d5cad47e5fbeda492 to your computer and use it in GitHub Desktop.
sitecore-di-example-blog-1.cs
public class FrontEndTestController : Controller
{
private IFrontEndTestRepository frontEndTestRepository;
// Poor man's DI. We want to get rid of this.
public FrontEndTestController() : this(new FrontEndTestRepository())
public FrontEndTestController(IFrontEndTestRepository frontEndTestRepository)
{
this.frontEndTestRepository = frontEndTestRepository;
}
public ViewResult GetFrontEndTestView()
{
var dataSourceId = RenderingContext.Current?.Rendering?.DataSource;
var viewModel =
dataSourceId != null
? frontEndTestRepository.GetFrontEndTestModel(dataSourceId)
: new FrontEndTest();
return View("FrontEndTest", viewModel);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment