How michelmichels/bpostsharp works
Overall Structure and Components
• Core Component (MichelMichels.BpostSharp): This is where the core interfaces (ICacheBuilder, ICityDataService) and models (such as CityData) are defined.
• Cache Builder Implementations:
• Excel Cache Builder (MichelMichels.BpostSharp.Excel): Implements ICacheBuilder by reading .xls files (relying on an external dependency like NPOI).
• CSV Cache Builder (MichelMichels.BpostSharp.Csv): Implements ICacheBuilder by reading CSV files.
• Web Cache Builder (MichelMichels.BpostSharp.Web): Implements ICacheBuilder by fetching and parsing HTML content online.
• Demo Application (MichelMichels.BpostSharp.Demo): A sample WPF application (using XAML, ViewModels, and Services) showing how to integrate the library.
• Test Suites: There are unit test projects for each implementation (Excel, CSV, Web) that validate the functionality, completeness, and correctness of the service operations (e.g., retrieving Belgian city data).
Relationships and Data Flow
• The core service (BelgianCityDataService) depends on an implementation of ICacheBuilder (which is provided by one of the cache builders). This dependency is injected, as seen in the example code.
• The Demo application demonstrates the interaction between the UI, a service layer (ApplicationHostService, MainViewModel), and the core service for querying data.
• Each cache builder is used to “build” or refresh the internal cache based on the input data (Excel/CSV file or web endpoint), after which queries (filtering by postal code or city name) are executed.
• The test projects simulate these interactions with provided resource files to ensure the cache builders behave as expected.
Architectural Patterns and Design Principles
• Separation of Concerns: The core functionality (data models and service interfaces) is separated from the cache building implementations.
• Dependency Injection: The service accepts an ICacheBuilder in its constructor, which allows different behaviors (Excel, CSV, Web) to be plugged in.
• Modular Design: Distinct NuGet packages (and project references) for Excel, CSV, and Web facilitate extensibility without overlapping responsibilities.
• Layered Architecture: At the top sits the demo/UI layer (for client interaction); the middle layer contains the service and caching logic; the data layer is abstracted by the cache builders.