Iuserrepository, Where Is the Implementation Code?
I'm Trying to Implement Simpleinjector to Use Dependency Injector but the Exammple on the Website Uses Iuserrepository Interface but There Is No Info About...
I'm trying to implement SimpleInjector to use Dependency Injector but the exammple on the website uses IUserRepository interface but there is no info about where it is comming from.
Could help me to know where is the implementation.
protected void Application_Start(object sender, EventArgs e)
{
// Create the container as usual.
var container = new Container();
// Register your types, for instance:
container.Register<IUserRepository, SqlUserRepository>();
container.RegisterPerWcfOperation<IUnitOfWork, EfUnitOfWork>();
// Register the container to the SimpleInjectorServiceHostFactory.
SimpleInjectorServiceHostFactory.SetContainer(container);
}
2 Answers
As John stated, those are just examples.
Assuming you created your own class and interface:
public interface IOrderService
{
void CancelOrder(int orderId);
}
public class SqlOrderService : IOrderService
{
public void CancelOrder(int orderId) { /* logic here */ }
}
You'd register it similar to their example, like this:
container.Register<IOrderService, SqlOrderService>();
Later on, when you request an IOrderService (such as in the constructor of another class), you'll actually get a concrete SqlOrderService instance.
So their example:
container.Register<IUserRepository, SqlUserRepository>();
Would suggest they have a class structure like this:
public interface IUserRepository
{
...
}
public SqlUserRepository : IUserRepository
{
...
}
The IUserRepository is something that you would have created (along with SqlUserRepository). They are just showing an example of how their injection works.