ltbaogt
ltbaogt

Reputation: 55

Web Api using parameterized constructor using Autofac

I'm converting Smartstore.Net project to WebApi and I want to create an API to get all Product from Smartstore.Net database. Here is my Get property and method:

IRepository<Product> productRepository;
public IEnumerable<Product> Get()
{
    var query = from p in _productRepository.Table
        orderby p.Name
        where p.Published && !p.Deleted && p.ShowOnHomePage
        select p;

    var products = query.ToList();
    return products;
}

Next step I found that _productRepository interface have to exsist through parameterized constructor of Api Controller. Then I have read Autofac do that (here is link) but i can't find class that implements IRepository interface.

Everyboy used Smartstore.Net can help me create an example API to get all product or help me found class that implements IRepository interface ?

Thanks alot ! ! !

Upvotes: 0

Views: 353

Answers (1)

user3536787
user3536787

Reputation: 26

SmartStore.NET 2.0.1 already has integrated support for WebApi. Please have a look here.

No need to create your own interface. If you want to expose your custom entities' Api, just inherit from WebApiEntityController<TEntity, TService>. The repository and service implementations will be injected automatically for you.

Upvotes: 1

Related Questions