Will IoC result in too many parameters for the ASP.NET MVC Controller constructor?

I decided to use ASP.NET MVC for the website project and want to follow some of the best practices that are written about.

So, I selected the domain / model in a separate project, created IRepositories and specific repositories, and now turned my attention to Castle Windsor as an IoC .

The problem that I am facing right now is that for a specific controller on the constructor I will have to go through several IRepository parameters.

My questions:

  • Perhaps I created too many repositories - in general, I map 1 repository to 1 entity class in 1 database table. Should my repositories effectively contain more than one / db entity table?
  • I missed the point with IoC and Injection Dependency Injection, and should I not worry about how params are passed to the Controller constructor?

To give some kind of context. Part of the website will display a map of Google properties, which can be found by type of property (castle, house, pub, etc.), location (zip code, city), opening time, etc. Thus, these searchable components are all individual ObjectType, Address.City, Address.Postcode.Lat + Long, OpeningTime.DateTime objects. Therefore, there are also 3 separate repositories that must be passed to the SearchController constructor.

, , .

, .

.

+3
1

, , IoC .

, , , .

, , Entity . , . . :

interface IRepository<T>
{
    IQueryable<T> GetAll();
    T GetOne(int id);
    void Save(T item);
    void Delete(T item);
}

class OrderService
{
    public OrderService(IReopository<Order> orderRepository, IRepository<OrderDetail> orderDetailRepository, IRepository<Payment> paymentRepository, etc) { }

    public Order CreateOrder(List<OrderDetails> details)
    {}
    // .. other aggregate methods
}
+3

Source: https://habr.com/ru/post/1708487/


All Articles