jeudi 16 septembre 2021

How to avoid duplicate class and method names when getting data from multiple sources?

I am working on a .NET 5 based web application which reads data from many different data sources. In many cases, data which belongs together in my application is often stored in up to four different data sources, such as an SQL Server database or in Azure Time Series Insights.

To make working with the data as simple as possible in my application, I often bundle the data together in DTOs before working with it in my business logic or in the frontend. To do this I created a "DataAccess" project in my solution and added a folder for every data source I need to read data from. In each of those folders I added one or more accessor classes which contain methods and functions for reading or writing data to/from the corresponding data source. In the root folder of my DataAccess project I then have accessor classes which use the accessor classes for the individual data sources to read the data and bundle it into the DTO objects. Here is an example for how the project structure looks like in the solution explorer:

enter image description here

As can be seen, this unfortunately results in many identically named classes (and functions/methods) which can be confusing to work with, especially the more complex the project will get over time. As a solution I was thinking about renaming the classes for the individual data sources so that they also contain the name of the data source, for example "TimeSeriesInsightsDeviceAccessor". While this would work just fine, it would make many of the class names very long (sometimes up to 40+ characters).

Is there a way to do this without ending up with many identically named classes or with very long class names?

Aucun commentaire:

Enregistrer un commentaire