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 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);
}
1

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
{
    ...
}
4

The IUserRepository is something that you would have created (along with SqlUserRepository). They are just showing an example of how their injection works.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest