DeftFlux.Azure.ServiceBus.Manager 1.0.0.15

dotnet add package DeftFlux.Azure.ServiceBus.Manager --version 1.0.0.15
                    
NuGet\Install-Package DeftFlux.Azure.ServiceBus.Manager -Version 1.0.0.15
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DeftFlux.Azure.ServiceBus.Manager" Version="1.0.0.15" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DeftFlux.Azure.ServiceBus.Manager" Version="1.0.0.15" />
                    
Directory.Packages.props
<PackageReference Include="DeftFlux.Azure.ServiceBus.Manager" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DeftFlux.Azure.ServiceBus.Manager --version 1.0.0.15
                    
#r "nuget: DeftFlux.Azure.ServiceBus.Manager, 1.0.0.15"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DeftFlux.Azure.ServiceBus.Manager@1.0.0.15
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DeftFlux.Azure.ServiceBus.Manager&version=1.0.0.15
                    
Install as a Cake Addin
#tool nuget:?package=DeftFlux.Azure.ServiceBus.Manager&version=1.0.0.15
                    
Install as a Cake Tool

DeftFlux Azure Service Bus Manager

Project Description

DeftFlux Azure Service Bus Manager is a .NET library that simplifies working with Azure Service Bus topics and messages. It provides a structured approach to creating, managing, and processing Service Bus messages with built-in serialization, validation, and type safety features.

The library offers:

  • Type-safe message handling through generic base classes
  • Built-in JSON serialization/deserialization for Service Bus messages
  • Validation support using data annotations
  • Easy dependency injection setup for .NET applications
  • Extensible architecture for custom topic implementations

Features

  • 🚀 Simple Setup: Easy integration with .NET dependency injection
  • 🔒 Type Safety: Generic constraints ensure compile-time type safety
  • 📝 Validation: Built-in support for data annotation validation
  • 🔄 Serialization: Automatic JSON serialization/deserialization
  • 🎯 Extensible: Easy to extend with custom topic classes
  • 📦 Lightweight: Minimal dependencies and overhead

Installation

Add the package reference to your project:

<PackageReference Include="DeftFlux.Azure.ServiceBus.Manager" Version="1.0.0" />

Setup in Program.cs

To set up the Service Bus Manager as a service in your application, add the following configuration to your Program.cs:

using DeftFlux.Azure.ServiceBus.Manager.Services;
using DeftFlux.Azure.ServiceBus.Manager.Services.Interfaces;

var builder = WebApplication.CreateBuilder(args);

// pull settings for section "ServiceBusSettings" from configuration and set to ServiceBusSettings object variable
var settings = builder.Configuration.GetSection("ServiceBusSettings").Get<ServiceBusSettings>();

builder.Services.AddSingleton<IConfiguration>(builder.Configuration);

// Add Azure Service Bus Manager
builder.Services.AddServiceBusServiceScoped<ExampleTopicObject>(settings);

var app = builder.Build();

app.Run();

You'll also need to add your Azure Service Bus connection string to your appsettings.json:

{
  "ServiceBusSettings": {
    "ServiceBusConnectionString": "Endpoint=sb://blablabla;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;",
    "SubscriptionName": "SubscriptionName",
    "AutoComplete": true,
    "StartOnRegister": true,
    "MaxConcurrentCalls": 1
  }
}

Creating Custom Topic Classes

To define your own custom topic classes, inherit from the TopicBase<T> abstract class. This base class provides JSON serialization/deserialization functionality through the ITopic<T> interface.

Example Custom Topic

Here's how to create a custom topic class:

using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using DeftFlux.Azure.ServiceBus.Manager.Topics;

public class OrderTopic : TopicBase<OrderTopic>
{
    [Required]
    public int OrderId { get; set; }

    [Required]
    [StringLength(100, MinimumLength = 1)]
    public string CustomerName { get; set; } = string.Empty;

    [Required]
    [Range(0.01, double.MaxValue)]
    public decimal TotalAmount { get; set; }

    [JsonIgnore]
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

    public bool IsValid()
    {
        var context = new ValidationContext(this);
        return Validator.TryValidateObject(this, context, null, true);
    }
}

Key Features of TopicBase<T>

The TopicBase<T> class provides:

  • JSON Serialization: ToJson() method to convert your topic to JSON string
  • JSON Deserialization: FromJson(string json) method to create topic instances from JSON
  • Type Safety: Generic constraint ensures type safety during serialization/deserialization

Usage Example

// Create a new topic instance
var orderTopic = new OrderTopic
{
    OrderId = 123,
    CustomerName = "John Doe",
    TotalAmount = 99.99m
};

// Serialize to JSON
string json = orderTopic.ToJson();

// Deserialize from JSON
var deserializedOrder = new OrderTopic().FromJson(json);

Best Practices

  1. Validation: Implement validation using data annotations and the IsValid() method
  2. Required Fields: Use [Required] attribute for mandatory properties
  3. JSON Ignore: Use [JsonIgnore] for properties that shouldn't be serialized
  4. Naming: Use descriptive names that reflect the message content
  5. Versioning: Consider versioning strategies for topic evolution

Requirements

  • .NET 6.0 or higher
  • Azure Service Bus namespace
  • Valid Azure Service Bus connection string

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For questions and support, please open an issue in the GitHub repository.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0.15 224 8/8/2025
1.0.0.14 272 8/5/2025
1.0.0.13 241 8/5/2025
1.0.0.12 217 8/4/2025
1.0.0.11 217 8/4/2025
1.0.0.10 378 7/25/2025
1.0.0.9 400 7/25/2025
1.0.0.8 406 7/25/2025
1.0.0.6 507 7/24/2025
1.0.0.5 503 7/24/2025