I have a design problem in my WEB API .NET CORE.
In my application users can search anything with keywords, results is a range of different business object, here a schema to explain :
We do not know what the user search and what he is looking for, we can return bank accounts, or users,... or a mixture of all type.
Model like BankAccountModel,UserModel,... are objects that are also used outside of research.
In UI, results is like thumbnail with different information depending on the type
So, for that, i have a "Marker interface" : ISearchResult ( empty interface ) to identify all "searchResult"
And my service SearchEngineService call each implementation of ISearchCriteria to get a result
foreach (Type type in Assembly.GetExecutingAssembly()
.GetTypes()
.Where(mytype => mytype.GetInterfaces().Contains(typeof(ISearchCriteria))))
{
var criteria = ((ISearchCriteria)ActivatorUtilities.CreateInstance(_provider, type));
List<ISearchResult> results=criteria .GetContent(filtresMoteurRecherche.TexteRecherche)
//TODO return AddAll blablabla
}
so my problem is :
-How can avoid this marker interface?
-And Bonus: is this a good way to use ISearchCriteria to separate each search and scan all implementation ? (because each search can make 100+ lines of code)
thank you
question from:
https://stackoverflow.com/questions/65907723/asp-net-core-service-design-with-generic-objects-how-can-i-avoid-marker-inter 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…