Transmitly.Microsoft.Extensions.DependencyInjection 0.2.1

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Transmitly.Microsoft.Extensions.DependencyInjection --version 0.2.1
                    
NuGet\Install-Package Transmitly.Microsoft.Extensions.DependencyInjection -Version 0.2.1
                    
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="Transmitly.Microsoft.Extensions.DependencyInjection" Version="0.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Transmitly.Microsoft.Extensions.DependencyInjection" Version="0.2.1" />
                    
Directory.Packages.props
<PackageReference Include="Transmitly.Microsoft.Extensions.DependencyInjection" />
                    
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 Transmitly.Microsoft.Extensions.DependencyInjection --version 0.2.1
                    
#r "nuget: Transmitly.Microsoft.Extensions.DependencyInjection, 0.2.1"
                    
#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 Transmitly.Microsoft.Extensions.DependencyInjection@0.2.1
                    
#: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=Transmitly.Microsoft.Extensions.DependencyInjection&version=0.2.1
                    
Install as a Cake Addin
#tool nuget:?package=Transmitly.Microsoft.Extensions.DependencyInjection&version=0.2.1
                    
Install as a Cake Tool

Transmitly.Microsoft.Extensions.Dependencyinjection

A Transmitly extension to help with configuring a communications client using Microsoft Dependency Injection.

Getting started

To use the dependency injection extension, first install the NuGet package:

dotnet add package Transmitly.Microsoft.Extensions.Dependencyinjection

Then start configuring...

using Transmitly;
...

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddTransmitly(tly=>{
	//Check out the Transmit.ly project for details on configuration options!
});

  • Check out the Transmitly project for more details on how to configure a communications client as well as how it can be used to improve how you manage your customer communications.

Advanced Configuration

If you need to access a database or service or just in general need to access services via dependency injection consdering registring an ICommunicationsClientConfigurator object to give yourself more control.

First we'll create implement the ICommunicationsClientConfigurator

MyPlatformCommsConfig.cs

public class MyPlatformCommsConfig : ICommunicationsClientConfigurator
{
    private readonly IOptions<TransmitlySettings> _options;
    private readonly ICommunicationsPipelineConfigurator[] _pipelineConfigurators;

    // ICommunicationsPipelineConfigurator would be a custom inteface and you would be responsible for registering these implementations.
    public MyPlatformCommsConfig(IOptions<TransmitlySettings> options, IEnumerable<ICommunicationsPipelineConfigurator> pipelineConfigurators) 
    {
        _options = options;
        _pipelineConfigurators = [.. pipelineConfigurators];
    }

    public void ConfigureClient(CommunicationsClientBuilder cfg)
    {
        var transmitlySettings = _options.Value;

        cfg
        .AddTwilioSupport(twilio =>
        {
            var twilioConfig = transmitlySettings.ChannelProviders.Twilio;

            twilio.AuthToken = twilioConfig.AuthToken;
            twilio.AccountSid = twilioConfig.AccountSid;
        })
        .AddSmtpSupport(smtp =>
        {
            var smtpConfig = transmitlySettings.ChannelProviders.Smtp;

            smtp.Host = smtpConfig.Host;
            smtp.Port = smtpConfig.Port;
            smtp.UserName = smtpConfig.UserName;
            smtp.Password = smtpConfig.Password;
        });
    }

    private void ConfigurePipelines(CommunicationsClientBuilder cfg)
    {
        foreach (var communicationsPipelineConfigurator in _pipelineConfigurators)
        {
            cfg.AddPipeline(communicationsPipelineConfigurator.Name, cfg =>
            {
                communicationsPipelineConfigurator.Configure(cfg);
            });
        }
    }

}

If you're familiiar with Transmitly, it's doing all the same things you're familiar with. The difference is you can now use registered classes and interfaces from your app's registration. This exmpale allows you to pull your config from jsut about anywhere. It also allows you to define custom pipeline configurators. These would allow you to spread your pipline configuration by domain, service, team or just about any way that makes sense for your team.

Example Pipline Configurator

public class MyOrderPlacePipeline : ICommunicationsPipelineConfigurator
{
  public string Name => "ordering.placement.thankyou";

  public void Configure(IPipelineConfiguration pipeline)
  {
    pipeline
      .AddEmail("from@example.com".AsIdentityAddress(), email =>
      {
        email.Subject.AddStringTemplate("Transmit.ly order receipt: {{OrderId}}");
        email.HtmlBody.AddStringTemplate("<h1>Thank you for your order {{aud.FirstName}}</h1><p>Totaling ${{GrandTotal}}.  Your order id is {{OrderId}}.</p>");
        email.TextBody.AddStringTemplate("Thank you for your order {{aud.FirstName}}, totaling ${{GrandTotal}} dollars.  Your order id is {{OrderId}}.");
      })
      .AddVoice("18881234567".AsIdentityAddress(), sms =>
      {
        sms.Message.AddStringTemplate("Thank you for your order {{aud.FirstName}}, totaling {{GrandTotal}} dollars.  Your order id is {{OrderId}}");
      });
  }
}

Next, we'll need to let Transmitly know you're taking going to take control over the configuration in our MyPlatformCommsConfig class

Program.cs

using Transmitly;
...

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddTransmitly<MyPlatformCommsConfig>();

Yup, it's that simple. Now when you resolve an ICommunicationsClient your custom MyPlatformCommsConfig will be called.

Still need more control?

If implementing your own ICommunicationsClientConfigurator isn't enough control. Consider also registering your own custom ICommunciationsClient implementations

MyCustomClient

public class InjectedConfiguredCommunicationsClient : ICommunicationsClient
{
  private readonly Lazy<ICommunicationsClient> _lazy;

  public InjectedConfiguredCommunicationsClient(ICommunicationsClientConfigurator configurator)
  {
    _lazy = new Lazy<ICommunicationsClient>(() =>
    {
      var cfg = new CommunicationsClientBuilder();
      configurator.ConfigureClient(cfg);
      return cfg.BuildClient();
    });
  }

  public ICommunicationsClient Client
  {
    get
    {
      return _lazy.Value;
    }
  }

  public void DeliverReport(DeliveryReport report)
  {
    Client.DeliverReport(report);
  }

  public void DeliverReports(IReadOnlyCollection<DeliveryReport> reports)
  {
    Client.DeliverReports(reports);
  }

  public Task<IDispatchCommunicationResult> DispatchAsync(string pipelineName, IReadOnlyCollection<IPlatformIdentityProfile> platformIdentities, ITransactionModel transactionalModel, IReadOnlyCollection<string> channelPreferences, string? cultureInfo = null, CancellationToken cancellationToken = default)
  {
    return Client.DispatchAsync(pipelineName, platformIdentities, transactionalModel, channelPreferences, cultureInfo, cancellationToken);
  }

  public Task<IDispatchCommunicationResult> DispatchAsync(string pipelineName, IReadOnlyCollection<IPlatformIdentityReference> identityReferences, ITransactionModel transactionalModel, IReadOnlyCollection<string> channelPreferences, string? cultureInfo = null, CancellationToken cancellationToken = default)
  {
    return Client.DispatchAsync(pipelineName, identityReferences, transactionalModel, channelPreferences, cultureInfo, cancellationToken);
  }

Registration example

using Transmitly;
...

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddTransmitly<MyPlatformCommsConfig, InjectedConfiguredCommunicationsClient>();

Registering your own communications client gives you the ultimate flexibility and control over configuration, and execution of your notifications.

<picture> <source media="(prefers-color-scheme: dark)" srcset="https://github.com/transmitly/transmitly/assets/3877248/524f26c8-f670-4dfa-be78-badda0f48bfb"> <img alt="an open-source project sponsored by CiLabs of Code Impressions, LLC" src="https://github.com/transmitly/transmitly/assets/3877248/34239edd-234d-4bee-9352-49d781716364" width="350" align="right"> </picture>


Copyright © Code Impressions, LLC - Provided under the Apache License, Version 2.0.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
0.2.2-2.11f7421 9 8/17/2025
0.2.1 88 7/29/2025