|
| 1 | +# SignNow .NET SDK Development Guide |
| 2 | + |
| 3 | +## Overview & Purpose |
| 4 | + |
| 5 | +This is the official .NET SDK for SignNow's electronic signature API, targeting .NET Framework 4.6.2+, .NET Standard 2.0/2.1, and modern .NET versions. The SDK follows a service-oriented architecture and provides a simple, modern, and efficient way to interact with the SignNow API. |
| 6 | + |
| 7 | +## High-Level Architecture |
| 8 | + |
| 9 | +This SDK is designed as cross-platform library with service-oriented architecture, supporting asynchronous programming patterns and strong typing. |
| 10 | + |
| 11 | +- **Project Type**: Class Library targeting multiple frameworks |
| 12 | +- **Architecture**: Service-oriented with clear separation of concerns |
| 13 | +- **Distribution**: Available via NuGet package manager |
| 14 | +- **Target Frameworks**: Multi-targeted for `.NET Core` and `.NET Framework 4.6.2` with support of standards - .NET Standard 2.0/2.1 |
| 15 | +- **Key Design Patterns**: |
| 16 | + - **Dependency Injection (DI)**: The SDK is designed to be easily integrated into DI containers with minimal configuration (`SignNowContext` as the main entry point). |
| 17 | + - **Service Layer**: Core services are exposed via interfaces and represented by concrete classes in the `Service` folder. |
| 18 | + - **Model Layer**: Comprehensive model classes represent API requests and responses, ensuring strong typing and JSON serialization. |
| 19 | + - **Infrastructure Layer**: HTTP client infrastructure, including request/response handling, exceptions handling is encapsulated in base classes. |
| 20 | + - **Async/Await**: Full support for asynchronous operations with cancellation tokens. |
| 21 | + - **Token Management**: Built-in support for OAuth2 authentication, including token acquisition and refresh mechanisms. |
| 22 | + |
| 23 | +## Solution & Project Structure |
| 24 | + |
| 25 | +``` |
| 26 | +├── SignNow.Net/ // Main SDK library |
| 27 | +│ ├── _Internal/ |
| 28 | +│ │ ├── Constants/ // API endpoint URLs, error messages, and other constants |
| 29 | +│ │ ├── Extensions/ // Extension methods for string manipulation, validation, etc. |
| 30 | +│ │ ├── Helpers/ // Utility classes for HTTP requests, serialization, validation |
| 31 | +| | │ ├── Converters/ // Custom JSON converters for complex types (e.g., Uri, Enums) |
| 32 | +│ │ ├── Infrastructure/ // Telemetry and platform-specific implementations |
| 33 | +│ │ ├── Model/ // Internal model classes not exposed publicly |
| 34 | +│ │ └── Requests/ // Internal request classes for complex operations |
| 35 | +│ ├── Exceptions/ // Custom exception classes for API errors |
| 36 | +│ ├── Interfaces/ // Public service interfaces |
| 37 | +│ ├── Model/ // All model classes for API requests/responses |
| 38 | +│ │ ├── ComplexTags/ // Complex tag types (e.g., SignatureTag, TextTag, etc.) |
| 39 | +│ │ ├── EditFields/ // Edit field types (e.g., TextField, CheckboxField, etc.) |
| 40 | +│ │ ├── FieldContents/ // Field content types (e.g., TextContent, CheckboxContent, etc.) |
| 41 | +│ │ ├── Requests/ // Request model classes |
| 42 | +│ │ └── Responses/ // Response model classes |
| 43 | +│ ├── Service/ // Service implementations |
| 44 | +│ │ ├── DocumentGroupService.cs // Document group operations service |
| 45 | +│ │ ├── DocumentService.cs // Document operations service |
| 46 | +│ │ ├── EventSubscriptionService.cs // Event subscription service |
| 47 | +│ │ ├── FolderService.cs // Folder management service |
| 48 | +│ │ ├── OAuth2Service.cs // OAuth2 token management service |
| 49 | +│ │ ├── SignNowClient.cs // Core HTTP client implementation |
| 50 | +│ │ ├── UserService.cs // User management service |
| 51 | +│ │ └── WebClientBase.cs // Base class for HTTP clients |
| 52 | +│ ├── SignNowContext.cs // Main entry point and DI container setup |
| 53 | +│ └── SignNow.Net.csproj // Multi-target SDK project file (.NET Framework 4.6.2+, .NET Standard 2.0/2.1) |
| 54 | +│ |
| 55 | +├── SignNow.Net.Examples/ // Usage examples and samples |
| 56 | +│ ├── Document group/ // Document group operations examples |
| 57 | +│ ├── Documents/ // Document operations examples |
| 58 | +│ ├── Folders/ // Folder management examples |
| 59 | +| ├── Invites/ // Event subscription examples |
| 60 | +│ ├── OAuth2/ // OAuth2 authentication examples |
| 61 | +│ ├── Template/ // Template management examples |
| 62 | +│ ├── TestExamples/ // Sample documents and templates for testing |
| 63 | +│ ├── Users/ // User management examples |
| 64 | +│ ├── Webhooks/ // Webhook management examples |
| 65 | +│ ├── ExamplesBase.cs // Base class for examples with common setup |
| 66 | +│ └── SignNow.Net.Examples.csproj // Example project file |
| 67 | +│ |
| 68 | +├── SignNow.Net.Test/ // Comprehensive test suite |
| 69 | +│ ├── AcceptanceTests/ // End-to-end acceptance tests |
| 70 | +│ ├── Constants/ // Test constants (e.g., error messages, test user IDs) |
| 71 | +│ ├── Context/ // Tests for Credentials loading and SignNowContext setup |
| 72 | +│ ├── FeatureTests/ // Feature-specific integration tests |
| 73 | +│ ├── TestData/ // Test fixtures and sample data |
| 74 | +│ │ ├── Documents/ // Sample documents for testing |
| 75 | +│ │ └── FakeModels // Fake model classes for generating test data |
| 76 | +│ ├── UnitTests/ // Unit tests with no external dependencies |
| 77 | +│ ├── AssertExtensions.cs // Custom assertion extensions for tests |
| 78 | +│ ├── AuthorizedApiTestBase.cs // Base class for tests requiring authorized API access |
| 79 | +│ ├── Directory.Build.props // Shared MSBuild properties for tests |
| 80 | +│ ├── SignNowTestBase.cs // Base class for all tests with common setup/teardown |
| 81 | +│ ├── SignNow.Net.Test.csproj // Test project targeting multiple frameworks |
| 82 | +│ └── TestUtils.cs // Utility methods for tests (e.g., JSON serialization) |
| 83 | +│ |
| 84 | +├── .editorconfig // Code formatting and style rules |
| 85 | +├── .netconfig // .NET runtime configuration (ReportGenerator configuration for codecoverage) |
| 86 | +├── CHANGELOG.md // SDK change log and release notes |
| 87 | +├── Directory.Build.props // Shared MSBuild properties and versioning |
| 88 | +├── netfx.props // .NET Framework specific build properties for multi-targeting and cross-platform support |
| 89 | +├── SignNow.Net.sln // Main solution file |
| 90 | +├── SignNow.props // Shared build properties for multi-targeting, versioning, and packaging (Nuget config) |
| 91 | +└── README.md // SDK documentation and getting started guide |
| 92 | +``` |
| 93 | + |
| 94 | +## Core Concepts & Implementation Details |
| 95 | + |
| 96 | +### Public API Surface |
| 97 | + |
| 98 | +- The public API is primarily defined by interfaces located in the `SignNow.Net/Interfaces` folder. |
| 99 | +- Consumers of the SDK should only need to depend on these interfaces and the models they expose. |
| 100 | +- All implementation classes with complex request transformations should be marked as `internal` and placed into `SignNow.Net/_Internal` folder. |
| 101 | +- All the public responses and request models are located in the `SignNow.Net/Model` folder. |
| 102 | +- All the entities of the SignNow API should be represented by strongly typed models. Models should be grouped by feature areas (e.g., `Document`, `User`, `Folder`, etc.) and further subdivided into `Requests` and `Responses` folders. |
| 103 | +- SignNow API entities could be grouped for re-usage purposes (e.g., `ComplexTags`, `EditFields`, `FieldContents`). The groups should be placed into separate folders under `Model` folder and represent single SignNow API entity. |
| 104 | +- Avoid exposing implementation details, such as HTTP client classes or internal helpers, in the public API. |
| 105 | +- For dynamic API responses, use internal Json converters to handle deserialization without exposing complexity to consumers. |
| 106 | + |
| 107 | +### Dependency Injection |
| 108 | + |
| 109 | +- The SDK provides a single entry point - `SignNowContext` with minimalistic parameters for configuration, like API base URL, Token (if any exists) and HTTP client. |
| 110 | +- This `SignNowContext` class registers all necessary services with a single context. |
| 111 | +- For User Authentication - use `SignNowContext.SetAppCredentials()` and `SignNowContext.GetAccessToken()` methods to configure application and user credentials respectively. |
| 112 | +- For advanced scenarios or re-usage of existing HTTP clients, the SDK provides an ability to set custom `ISignNowClient` implementation via `SignNowContext` constructor. |
| 113 | +- Application secrets and user credentials are not stored in the SDK, and should be managed by the consumer application. |
| 114 | + |
| 115 | +### Platform-Specific Code |
| 116 | + |
| 117 | +- The SDK targets multiple frameworks: .NET Framework 4.6.2, .NET Standard 2.0/2.1, and modern .NET versions (e.g., .NET 7.0/8.0). |
| 118 | +- To compile .NET SDK 2.x projects targeting .NET 4.x on Mono (Linux, macOS), we use `netfx.props` file with specific build properties for MSBuild system. |
| 119 | +- We use preprocessor directives (`#if NETSTANDARD`, `#if NET462`, `#if NETFRAMEWORK`) to compile code conditionally for each target. |
| 120 | +- Platform-specific and Framework-specific code is most commonly used for networking (e.g., `HttpClient` configuration) or file system differences. |
| 121 | +- All the business logic should be platform-agnostic and reusable across all target frameworks. |
| 122 | +- We use `System.Net.ServicePointManager` to enforce TLS 1.2 on .NET Framework 4.6.2, as it defaults to older protocols. |
| 123 | + |
| 124 | +### Error Handling |
| 125 | + |
| 126 | +- Exception handling should be consistent across platforms, with custom exceptions defined in the `Exceptions` folder. |
| 127 | +- The SDK throws own custom exceptions `SignNowException` with all the inner Exceptions and their details. |
| 128 | +- The SDK throws `ArgumentException`, `ArgumentNullException` for invalid method arguments or state. |
| 129 | +- Consumers should `try-catch` these specific exceptions to handle SDK-related errors gracefully. |
| 130 | +- Avoid throwing generic exceptions like `System.Exception` or specific for json conversion exception `JsonSerializationException`. All the exceptions should be wrapped into `SignNowException` with all the inner exceptions preserved. |
| 131 | + |
| 132 | +## Coding & Contribution Guidelines |
| 133 | + |
| 134 | +- **Style**: Follow the standard .NET coding conventions. Use the `.editorconfig` file provided in the repository. |
| 135 | +- **Testing**: Any new feature or bug fix must be accompanied by corresponding unit tests. |
| 136 | +- **Documentation**: All public types, methods, and properties must have XML documentation comments (`///`). |
| 137 | +- **Dependencies**: Minimize external dependencies. Before adding a new NuGet package, discuss it with the team. |
| 138 | +- **Change Log**: Update `CHANGELOG.md` with a summary of changes for each release and pull request. |
0 commit comments