(refactor): project naming and readme
This commit is contained in:
parent
7ab3e848ba
commit
76d32ee954
166
README.md
166
README.md
@ -1,6 +1,168 @@
|
||||
# MaksIT.Core.Dapr
|
||||
# MaksIT.Dapr
|
||||
|
||||
This repository hosts the `maksit-dapr` project, which utilizes [Dapr](https://dapr.io/) (Distributed Application Runtime) to facilitate building and managing microservices with ease. The project focuses on implementing a robust, scalable solution leveraging Dapr's building blocks and abstractions.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Overview](#overview)
|
||||
- [Features](#features)
|
||||
- [Getting Started](#getting-started)
|
||||
- [Prerequisites](#prerequisites)
|
||||
- [Installation](#installation)
|
||||
- [Configuration](#configuration)
|
||||
- [Usage](#usage)
|
||||
- [Running the Project](#running-the-project)
|
||||
- [Environment Variables](#environment-variables)
|
||||
- [Testing](#testing)
|
||||
- [Deployment](#deployment)
|
||||
- [Contributing](#contributing)
|
||||
- [License](#license)
|
||||
|
||||
## Overview
|
||||
|
||||
`maksit-dapr` serves as a foundational project to explore and implement Dapr-based microservices, demonstrating the integration of Dapr’s pub-sub, bindings, state management, and other building blocks in a distributed system environment.
|
||||
|
||||
## Features
|
||||
|
||||
- **Pub-Sub Integration**: Uses Dapr's pub-sub component for seamless event-driven communication.
|
||||
- **State Management**: Efficient, distributed state handling across microservices.
|
||||
|
||||
## Getting Started
|
||||
|
||||
Ensure that you have the following installed:
|
||||
|
||||
- [.NET 8.0 SDK](https://dotnet.microsoft.com/download)
|
||||
- [Docker](https://www.docker.com/get-started)
|
||||
|
||||
## Installation
|
||||
|
||||
To install MaksIT.Core, add the package to your project via NuGet:
|
||||
|
||||
```powershell
|
||||
dotnet add package MaksIT.Dapr
|
||||
```
|
||||
|
||||
Or manually add it to your .csproj file:
|
||||
|
||||
```powershell
|
||||
<PackageReference Include="MaksIT.Dapr" Version="1.0.0" />
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Registering Dapr Services
|
||||
|
||||
To use `maksit-dapr` in your application, you must register the provided services for dependency injection. Follow these steps to integrate Dapr's pub-sub and state management capabilities in your ASP.NET Core application:
|
||||
|
||||
1. **Register the Publisher and State Store Services**: Add these services in `Program.cs` or `Startup.cs`.
|
||||
|
||||
```csharp
|
||||
using MaksIT.Dapr.Extensions;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Register Dapr services
|
||||
builder.Services.RegisterPublisher();
|
||||
builder.Services.RegisterStateStore();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Set up Dapr subscriber middleware (optional)
|
||||
// Only after Webapi Authorization services
|
||||
app.RegisterSubscriber();
|
||||
```
|
||||
|
||||
2. **Use Controller as a Dapr Subscriber**:
|
||||
|
||||
To designate a controller as a Dapr subscriber, annotate it with the `[Topic("pubsubName", "name")]` attribute:
|
||||
|
||||
```csharp
|
||||
using Dapr;
|
||||
|
||||
[Topic("my-pubsub", "my-topic")]
|
||||
public class MyController : ControllerBase
|
||||
{
|
||||
[HttpPost("/my-endpoint")]
|
||||
public IActionResult ReceiveMessage([FromBody] MyCommand payload)
|
||||
{
|
||||
|
||||
|
||||
// Handle message
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Injecting and Using Dapr Services
|
||||
|
||||
With the services registered, you can inject `IDaprPublisherService` and `IDaprStateStoreService` into controllers or other services as needed:
|
||||
|
||||
```csharp
|
||||
using MaksIT.Dapr;
|
||||
|
||||
public class MyService
|
||||
{
|
||||
private readonly IDaprPublisherService _publisher;
|
||||
private readonly IDaprStateStoreService _stateStore;
|
||||
|
||||
public MyService(IDaprPublisherService publisher, IDaprStateStoreService stateStore)
|
||||
{
|
||||
_publisher = publisher;
|
||||
_stateStore = stateStore;
|
||||
}
|
||||
|
||||
public async Task PublishEventAsync()
|
||||
{
|
||||
var command = new MyCommand
|
||||
{
|
||||
CommandId = Guid.NewGuid(),
|
||||
CommandName = "SampleCommand",
|
||||
Timestamp = DateTime.UtcNow
|
||||
};
|
||||
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
};
|
||||
|
||||
var payload = JsonSerializer.Serialize(command, options);
|
||||
|
||||
var result = await _publisher.PublishEventAsync("my-pubsub", "my-topic", payload);
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
// Handle error
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SetStateAsync()
|
||||
{
|
||||
var saveResult = await _stateStore.SetStateAsync("my-store", "my-key", "my-value");
|
||||
if (!saveResult.IsSuccess)
|
||||
{
|
||||
// Handle error
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string?> GetStateAsync()
|
||||
{
|
||||
var stateResult = await _stateStore.GetStateAsync<string>("my-store", "my-key");
|
||||
return stateResult.IsSuccess ? stateResult.Value : null;
|
||||
}
|
||||
|
||||
public async Task DeleteStateAsync()
|
||||
{
|
||||
var deleteResult = await _stateStore.DeleteStateAsync("my-store", "my-key");
|
||||
if (!deleteResult.IsSuccess)
|
||||
{
|
||||
// Handle error
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This setup enables your ASP.NET Core application to utilize Dapr's pub-sub, state management, and other building blocks with minimal boilerplate.
|
||||
|
||||
MaksIT.Core.Dapr is a facade library for Dapr.
|
||||
|
||||
## Contributing
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.11.35327.3
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaksIT.Core.Dapr", "MaksIT.Core.Dapr\MaksIT.Core.Dapr.csproj", "{25AE0805-E014-4945-8BE8-D0DC2B4EB0FF}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaksIT.Dapr", "MaksIT.Dapr\MaksIT.Dapr.csproj", "{D6A8FD32-11E6-422E-9C33-B2D302B87562}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -11,10 +11,10 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{25AE0805-E014-4945-8BE8-D0DC2B4EB0FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{25AE0805-E014-4945-8BE8-D0DC2B4EB0FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{25AE0805-E014-4945-8BE8-D0DC2B4EB0FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{25AE0805-E014-4945-8BE8-D0DC2B4EB0FF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D6A8FD32-11E6-422E-9C33-B2D302B87562}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D6A8FD32-11E6-422E-9C33-B2D302B87562}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D6A8FD32-11E6-422E-9C33-B2D302B87562}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D6A8FD32-11E6-422E-9C33-B2D302B87562}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -4,7 +4,7 @@ using Dapr.Client;
|
||||
|
||||
using MaksIT.Results;
|
||||
|
||||
namespace MaksIT.Core.Dapr;
|
||||
namespace MaksIT.Dapr;
|
||||
|
||||
public interface IDaprPublisherService {
|
||||
Task<Result> PublishEventAsync(string pubSubName, string topicName, string payload);
|
||||
@ -17,7 +17,7 @@ public interface IDaprStateStoreService {
|
||||
}
|
||||
|
||||
public class DaprService : IDaprPublisherService, IDaprStateStoreService {
|
||||
private const string _errorMessage = "MaksIT.Core.Dapr - Data provider error";
|
||||
private const string _errorMessage = "MaksIT.Dapr - Data provider error";
|
||||
|
||||
private readonly DaprClient _client;
|
||||
private readonly ILogger<DaprService> _logger;
|
||||
@ -1,6 +1,6 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace MaksIT.Core.Dapr.Extensions;
|
||||
namespace MaksIT.Dapr.Extensions;
|
||||
public static class ServiceCollectionExtensions {
|
||||
public static void RegisterPublisher(this IServiceCollection services) {
|
||||
services.AddDaprClient();
|
||||
@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
|
||||
namespace MaksIT.Core.Dapr.Extensions;
|
||||
namespace MaksIT.Dapr.Extensions;
|
||||
public static class WebApplicationExtensions {
|
||||
|
||||
/// <summary>
|
||||
@ -6,12 +6,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<!-- NuGet package metadata -->
|
||||
<PackageId>MaksIT.Core.Dapr</PackageId>
|
||||
<Version>1.0.3</Version>
|
||||
<PackageId>MaksIT.Dapr</PackageId>
|
||||
<Version>1.0.4</Version>
|
||||
<Authors>Maksym Sadovnychyy</Authors>
|
||||
<Company>MAKS-IT</Company>
|
||||
<Product>MaksIT.Core.Dapr</Product>
|
||||
<Description>MaksIT.Core.Dapr is a facade library for Dapr.</Description>
|
||||
<Product>MaksIT.Dapr</Product>
|
||||
<Description>MaksIT.Dapr is a facade library for Dapr.</Description>
|
||||
<PackageTags>dotnet;dapr;</PackageTags>
|
||||
<RepositoryUrl>https://github.com/MAKS-IT-COM/maksit-core-dapr</RepositoryUrl>
|
||||
<License>MIT</License>
|
||||
@ -10,7 +10,7 @@ $nugetSource = "https://api.nuget.org/v3/index.json"
|
||||
|
||||
# Define paths
|
||||
$solutionDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$projectDir = "$solutionDir\MaksIT.Core.Dapr"
|
||||
$projectDir = "$solutionDir\MaksIT.Dapr"
|
||||
$outputDir = "$projectDir\bin\Release"
|
||||
|
||||
# Clean previous builds
|
||||
|
||||
@ -13,7 +13,7 @@ nugetSource="https://api.nuget.org/v3/index.json"
|
||||
# Define paths
|
||||
scriptDir=$(dirname "$0")
|
||||
solutionDir=$(realpath "$scriptDir")
|
||||
projectDir="$solutionDir/MaksIT.Core.Dapr"
|
||||
projectDir="$solutionDir/MaksIT.Dapr"
|
||||
outputDir="$projectDir/bin/Release"
|
||||
|
||||
# Clean previous builds
|
||||
|
||||
Loading…
Reference in New Issue
Block a user