C# - MVC - Loose coupling and dependency injection and DI Container
Hello, i need to create a design pattern using
1 - Loose coupling
2 - dependency injection
3 - DI Container
I'm already write something for apply the DI, but i'm have a problem and i can't understand why??
please i need to help , let see my codes :
Class User :
public partial class User
{
public int Id { get; set; }
public string Username { get; set; }
public string Pwd { get; set; }
public string Email { get; set; }
public DateTime? TransDate { get; set; }
}
}
Model Context :
public partial class FavSolutinsModel : DbContext
{
public FavSolutinsModel()
: base("name=FavSolutinsModel")
{
}
public virtual DbSet<User> Users { get; set; }
}
Interface :
namespace FavSolutions.Interfaces
{
public partial interface IFavSolutions
{
List<User> GetAllUsers();
}
}
Services Or Respiratory :
namespace FavSolutions.Services
{
public class FavSolutionsServices : IFavSolutions
{
private FavSolutinsModel _context = new FavSolutinsModel();
private IFavSolutions _favServices;
public FavSolutionsServices(IFavSolutions favServices)
{
_favServices = favServices;
}
public List<User> GetAllUsers()
{
return _context.Users.ToList();
}
}
}
Finally , Controller :
namespace FavSolutions.Controllers
{
public class UsersController : Controller
{
private IFavSolutions _favServices;
public UsersController(IFavSolutions favServices)
{
_favServices = favServices;
}
public ActionResult Index()
{
var model = _favServices.GetAllUsers();
return View();
}
}
}
Database and web.confg 100% currectly , please I need to solve this problem, and show me the length of time where I can not track the code because of it
simple project in link here... thx u UW.
Aucun commentaire:
Enregistrer un commentaire