I am still very confused as to why and when to use Dependency Injection. If anyone could explain maybe using the below example that would be great, any other explanations would be appreciated.
Lets say I am creating a web-app that will save movie reviews written in C# with ASP.NET MVC 5. If I have the following Model code,
namespace MovieReviewProject.Models
{
public class MovieReviews
{
[Key]
public int ReviewID_int{ get; set; }
/// <summary>
/// Submitter email address
/// </summary>
public string EmailAddress_str{ get; set; }
/// <summary>
/// Movie name
/// </summary>
public string MoveName_str{ get; set; }
/// <summary>
/// The review
/// </summary>
public string Review_str { get; set; }
/// <summary>
/// The submission date from
/// </summary>
public DateTime SubmissionDate_dt { get; set; }
/// <summary>
/// The movie rating
/// </summary>
public int Rating_int { get; set; }
}
}
how would a class that provides the Controller with the List of all the reviews, adds an average for a movie, and more look like?
I know that DI is mostly used to allow for easier unit testing but other than that what are the perks to it? Is it worth going through old projects and make sure all the providers are using this principal?
MovieReviews
should beMovieReview
, since one object represents a single review, not many.