Skip to content

Commit

Permalink
Add OfX.Nats!
Browse files Browse the repository at this point in the history
  • Loading branch information
quyvu01 committed Jan 4, 2025
1 parent c9389c9 commit 7adf41f
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 41 deletions.
6 changes: 6 additions & 0 deletions OfX.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OfX.EntityFrameworkCore", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OfX.Grpc", "src\OfX.Grpc\OfX.Grpc.csproj", "{36F9049C-6A77-4EF7-9CE0-86A22CA36DEA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OfX.Nats", "src\OfX.Nats\OfX.Nats.csproj", "{4E3B4EB4-8A12-41A4-B630-2601414CE0F3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -30,6 +32,10 @@ Global
{36F9049C-6A77-4EF7-9CE0-86A22CA36DEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{36F9049C-6A77-4EF7-9CE0-86A22CA36DEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{36F9049C-6A77-4EF7-9CE0-86A22CA36DEA}.Release|Any CPU.Build.0 = Release|Any CPU
{4E3B4EB4-8A12-41A4-B630-2601414CE0F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E3B4EB4-8A12-41A4-B630-2601414CE0F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E3B4EB4-8A12-41A4-B630-2601414CE0F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E3B4EB4-8A12-41A4-B630-2601414CE0F3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
EndGlobalSection
Expand Down
68 changes: 30 additions & 38 deletions src/OfX.EntityFrameworkCore/README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,68 @@
# OfX.EntityFrameworkCore
# OfX-Nats

OfX.EntityFrameworkCore is an extension package for OfX that integrates with Entity Framework Core to simplify data fetching by leveraging attribute-based data mapping. This extension streamlines data retrieval using EF Core, reducing boilerplate code and improving maintainability.
OfX-Nats is an extension package for OfX that leverages Nats for efficient data transportation. This package provides a high-performance, strongly-typed communication layer for OfX’s Attribute-based Data Mapping, enabling streamlined data retrieval across distributed systems.

[Demo Project!](https://github.com/quyvu01/TestOfX-Demo)

---

## Introduction

OfX.EntityFrameworkCore extends the core OfX library by providing seamless integration with Entity Framework Core. This enables developers to automatically map and retrieve data directly from a database, leveraging the power of EF Core along with attribute-based data mapping.

For example, suppose you have a `UserId` property in your model, and you want to fetch the corresponding `UserName` and `Email` fields from the database. By using OfX.EntityFrameworkCore, you can annotate your model with attributes, and the library will handle data fetching for you.
Nats-based Transport: Implements Nats to handle data communication between services, providing a fast, secure, and scalable solution.

---

## Installation

To install the OfX.EntityFrameworkCore package, use the following NuGet command:
To install the OfX-Nats package, use the following NuGet command:

```bash
dotnet add package OfX-EFCore
dotnet add package OfX-Nats
```

Or via the NuGet Package Manager:

```bash
Install-Package OfX-EFCore
Install-Package OfX-Nats
```

---

## How to Use

### 1. Register OfX.EntityFrameworkCore
### 1. Register OfX-Nats

Add OfX-Nats to your service configuration during application startup:

Add OfX.EntityFrameworkCore to your service configuration during application startup:
For Client:

```csharp
builder.Services.AddOfXEntityFrameworkCore(cfg =>
{
cfg.AddAttributesContainNamespaces(typeof(WhereTheAttributeDefined).Assembly);
cfg.AddContractsContainNamespaces(typeof(SomeContractAssemblyMarker).Assembly);
cfg.AddHandlersFromNamespaceContaining<SomeHandlerAssemblyMarker>();
})
.AddOfXEFCore(options =>
{
options.AddDbContexts(typeof(TestDbContext));
options.AddModelConfigurationsFromNamespaceContaining<SomeModelAssemblyMarker>();
});
```
cfg.AddNats(config => config
config.UseNats((context, bus) =>
{
bus.Host(host, c =>
{
c.Username(userName);
c.Password(password);
});
bus.ConfigureEndpoints(context);
});
);

After installing the package OfX-EFCore, you can use the method `AddDbContexts()`, which takes `DbContext(s)` to executing.

### 2. Mark the model you want to use with OfXAttribute
Example:

```csharp
[OfXConfigFor<UserOfAttribute>(nameof(Id), nameof(Name))]
public class User
{
public string Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
});
```
That all! Let go to the moon!
That All, enjoy your moment!

Note: Currently, the Id type is supported for primitive type, in the next version. The strongly-type should be supported!

| Package Name | Description | .NET Version | Document |
|----------------------------------------------------------|-------------------------------------------------------------------------------------------------|--------------|---------------------------------------------------------------------------|
| [OfX](https://www.nuget.org/packages/OfX/) | OfX core | 8.0, 9.0 | [ReadMe](https://github.com/quyvu01/OfX/blob/main/README.md) |
| [OfX-EFCore](https://www.nuget.org/packages/OfX-EFCore/) | This is the OfX extension package using EntityFramework to fetch data | 8.0, 9.0 | This Document |
| [OfX-gRPC](https://www.nuget.org/packages/OfX-gRPC/) | OfX.gRPC is an extension package for OfX that leverages gRPC for efficient data transportation. | 8.0, 9.0 | [ReadMe](https://github.com/quyvu01/OfX/blob/main/src/OfX.Grpc/README.md) |
| Package Name | Description | .NET Version | Document |
|----------------------------------------------------------|-------------------------------------------------------------------------------------------------|--------------|------------------------------------------------------------------------------------------|
| [OfX](https://www.nuget.org/packages/OfX/) | OfX core | 8.0, 9.0 | [ReadMe](https://github.com/quyvu01/OfX/blob/main/README.md) |
| [OfX-EFCore](https://www.nuget.org/packages/OfX-EFCore/) | This is the OfX extension package using EntityFramework to fetch data | 8.0, 9.0 | [ReadMe](https://github.com/quyvu01/OfX/blob/main/src/OfX.EntityFrameworkCore/README.md) |
| [OfX-gRPC](https://www.nuget.org/packages/OfX-gRPC/) | OfX-gRPC is an extension package for OfX that leverages gRPC for efficient data transportation. | 8.0, 9.0 | [ReadMe](https://github.com/quyvu01/OfX/blob/main/src/OfX.Grpc/README.md) |
| [OfX-Nats](https://www.nuget.org/packages/OfX-Nats/) | OfX-Nats is an extension package for OfX that leverages Nats for efficient data transportation. | 8.0, 9.0 | This Document |

---
6 changes: 3 additions & 3 deletions src/OfX.Grpc/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OfX.gRPC
# OfX-gRPC

OfX.gRPC is an extension package for OfX that leverages gRPC for efficient data transportation. This package provides a high-performance, strongly-typed communication layer for OfX’s Attribute-based Data Mapping, enabling streamlined data retrieval across distributed systems.
OfX-gRPC is an extension package for OfX that leverages gRPC for efficient data transportation. This package provides a high-performance, strongly-typed communication layer for OfX’s Attribute-based Data Mapping, enabling streamlined data retrieval across distributed systems.

[Demo Project!](https://github.com/quyvu01/TestOfX-Demo)

Expand All @@ -14,7 +14,7 @@ gRPC-based Transport: Implements gRPC to handle data communication between servi

## Installation

To install the OfX.EntityFrameworkCore package, use the following NuGet command:
To install the OfX-gRPC package, use the following NuGet command:

```bash
dotnet add package OfX-gRPC
Expand Down
23 changes: 23 additions & 0 deletions src/OfX.Nats/OfX.Nats.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<LangVersion>default</LangVersion>
<Version>3.1.1</Version>
<PackageIcon>OfX.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\OfX\OfX.csproj"/>
<None Include="..\..\LICENSE" Pack="true" PackagePath="\"/>
<None Include="README.md" Pack="true" PackagePath="\"/>
<None Include="..\..\OfX.png">
<Pack>True</Pack>
<PackagePath/>
<Link>OfX.png</Link>
</None>
</ItemGroup>

</Project>
67 changes: 67 additions & 0 deletions src/OfX.Nats/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# OfX-Nats

OfX-Nats is an extension package for OfX that leverages Nats for efficient data transportation. This package provides a high-performance, strongly-typed communication layer for OfX’s Attribute-based Data Mapping, enabling streamlined data retrieval across distributed systems.

[Demo Project!](https://github.com/quyvu01/TestOfX-Demo)

---

## Introduction

Nats-based Transport: Implements Nats to handle data communication between services, providing a fast, secure, and scalable solution.

---

## Installation

To install the OfX-Nats package, use the following NuGet command:

```bash
dotnet add package OfX-Nats
```

Or via the NuGet Package Manager:

```bash
Install-Package OfX-Nats
```

---

## How to Use

### 1. Register OfX-Nats

Add OfX-Nats to your service configuration during application startup:

For Client:

```csharp
builder.Services.AddOfXEntityFrameworkCore(cfg =>
{
cfg.AddContractsContainNamespaces(typeof(SomeContractAssemblyMarker).Assembly);
cfg.AddHandlersFromNamespaceContaining<SomeHandlerAssemblyMarker>();
cfg.AddNats(config => config
config.UseNats((context, bus) =>
{
bus.Host(host, c =>
{
c.Username(userName);
c.Password(password);
});
bus.ConfigureEndpoints(context);
});
);

});
```
That All, enjoy your moment!


| Package Name | Description | .NET Version | Document |
|----------------------------------------------------------|-------------------------------------------------------------------------------------------------|--------------|------------------------------------------------------------------------------------------|
| [OfX](https://www.nuget.org/packages/OfX/) | OfX core | 8.0, 9.0 | [ReadMe](https://github.com/quyvu01/OfX/blob/main/README.md) |
| [OfX-EFCore](https://www.nuget.org/packages/OfX-EFCore/) | This is the OfX extension package using EntityFramework to fetch data | 8.0, 9.0 | [ReadMe](https://github.com/quyvu01/OfX/blob/main/src/OfX.EntityFrameworkCore/README.md) |
| [OfX-gRPC](https://www.nuget.org/packages/OfX-gRPC/) | OfX.gRPC is an extension package for OfX that leverages gRPC for efficient data transportation. | 8.0, 9.0 | This Document |

---

0 comments on commit 7adf41f

Please sign in to comment.