I am super new to Dependency Injeection and using "Unity Mvc" as my DI container. I have a ProductRepository Class which is using my dbContext class to get data, however I would love to register my dbContext. here is what I have...
Partial Public Class websolutionsEntities
Inherits DbContext
' Code for dbContext Class
' This is my Repo, which I want to fix
Public Class productsRepository
Implements IProductRepository
' This line below I want to avoid, I dont want to rely on my dbContext for all repo's
Private _db As websolutionsEntities = New websolutionsEntities()
and here is my Unity Bootstrap:
Private Shared Function BuildUnityContainer() As IUnityContainer
Dim container = New UnityContainer()
' register all your components with the container here
' e.g. container.RegisterType<ITestService, TestService>();
container.RegisterType(Of IProductRepository, productsRepository)()
Return container
End Function
What do i need to do, so in my Repo i can avoid creating a new instance of dbContect class?