I have an ASP.NET MVC application that has my controller calling a command invoker to execute CRUD operations. The command handlers are in my Domain Layer assembly. One of the command handlers saves a record using the following code:
public class SaveTransactionCommandHandler : ICommandHandler<SaveTransactionCommand>
{
public void Handle(SaveTransactionCommand command)
{
using (GiftCardEntities db = new GiftCardEntities())
{
db.Transactions.AddObject(new Transaction
{
GiftCardId = command.GiftCardId,
TransactionTypeId = Convert.ToInt32(command.TransactionTypeId),
Amount = command.Amount,
TransactionDate = DateTime.Now
});
db.SaveChanges();
}
}
}
However, as you can see, my handler depends on an ObjectContext (EF). I'm in the process of learning Dependency Injection with Ninject. Now I know that my handler (domain object) should not be dependent on any data layer objects. But in my case the handler is dependent on GiftCardEntities which is an ObjectContext. How do I change my handler so that it is decoupled from the ObjectContext?