How managedcode/storage works
Main Components
• Core Library (ManagedCode.Storage.Core): Contains all the shared interfaces, base classes (e.g., IStorage, BaseStorage), common models, extensions (like ServiceCollectionExtensions), and helper classes.
• Storage Provider Implementations: Separate modules for each provider located under the “Storages” directory. These include:
– ManagedCode.Storage.Azure
– ManagedCode.Storage.Aws
– ManagedCode.Storage.Google
– ManagedCode.Storage.FileSystem
• Integration Components: Located under “Integraions” (such as ManagedCode.Storage.Client and ManagedCode.Storage.Server). These enable the library to work with ASP.NET and other hosting environments by supplying SignalR clients, extension methods for controllers, and background services.
• Test Infrastructure: Under “Tests” and “ManagedCode.Storage.TestFakes” which simulate various storage providers and demonstrate usage.
Relationships and Interactions
• At the top level, clients (for example, services in an ASP.NET application) inject an IStorage instance (or the provider-specific interface) into their constructors. This is achieved by using dependency injection and extension methods such as AddAzureStorage, AddAWSStorage, etc.
• The extension methods (found in several projects like the core and provider-specific extensions folders) register corresponding implementations with the DI container.
• Once registered, the universal IStorage abstraction internally resolves to a provider-specific implementation (e.g., IAzureStorage, IAWSStorage). Dependency inversion and factory patterns (e.g., using IStorageFactory) help abstract the differences.
• The “Core” library components call upon additional helper classes, such as those for stream handling (see Crc32Helper.cs, StreamHelper.cs) and provider creation logic.
• The integration layers (found under “Integraions/ManagedCode.Storage.Server”) offer additional functionality like controller extensions and background services for setup or maintenance of storage connections.
• The “TestFakes” module provides test doubles for cloud providers, making it easier to simulate provider behavior in testing scenarios.
Architectural Patterns and Design Principles
• Use of Dependency Injection: The extension methods tie together configuration and concrete storage implementations.
• Factory/Strategy Pattern: The library uses factories (via IStorageFactory) to select the appropriate storage provider at runtime.
• Abstraction and Wrapping: The idea is to wrap the indigenous APIs (Azure SDK, AWS S3, Google Cloud client libraries, file system operations) behind uniform interfaces.
• Separation of Concerns: Core/shared functionality is kept independent of storage-specific code, enabling easier maintenance and extension.