mercredi 8 avril 2020

Design Pattern for Multiple Providers and single subject

This is a design related question.

I am building an application which uses Lucene.Net indexes to facilitate search for various entities like User, Client etc. I am using MSSQL as database and the indexes are made on startup.

The code structure looks like this:

DebtorController --> SearchService --> SearchProvider --> LuceneIndexRepository` 

Controller calls SearchService which has the GetDebtors method

public Core.Models.PagedResult<Debtor> GetDebtors(Core.Models.FilterParameter parameter)
    {
        var result = new Core.Models.PagedResult<Debtor>();
        var debtorResult = _searchProvider.GetDebtors(parameter.SearchKeyword);
        result.TotalCount = debtorResult.Count;
        result.Results = debtorResult
            .AsQueryable()
            .OrderBy(SetSortOrder(parameter.SortBy, parameter.SortDirection))
           .Skip((parameter.PageNumber - 1) * parameter.PageSize)
           .Take(parameter.PageSize).ToList();
        return result;
    }

The SearchProvider converts the Lucene Documents into entities and LuceneIndexRepository<T> takes care of the search and indexes where <T> is an entity like User, Debtor and Client.

Now, I am looking at a pattern which would call call the AppendIndex and UpdateDocument method via an Observer in order to keep the Lucene indexes updated.

One way is to call the Append and Update methods manually, however I was also looking for the Observer design pattern, but it works for single Provider and multiple Subjects which listen to the updates. In my case I have multiple providers and a single observer, which is of Generic type. Please let me know the best design practice for the same which would decouple the tasks.

Aucun commentaire:

Enregistrer un commentaire