Skip to content

Commit d881485

Browse files
KennethScottKenneth Scott
andauthored
πŸ”€ ✨ feat: allow GraphServiceClient to be passed in (#143)
* Add new constructor allowing the GraphServiceClient to be passed in * Add new signature to AddGraphSender allowing GraphServiceClient to be passed in Co-authored-by: Kenneth Scott <k_e_n_n_e_t_h_s_c_o_t_t@hotmail.com>
1 parent 2db3a6d commit d881485

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

β€Žsrc/FluentEmail.Graph/FluentEmailServicesBuilderExtensions.csβ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using FluentEmail.Core.Interfaces;
44
using Microsoft.Extensions.DependencyInjection;
55
using Microsoft.Extensions.DependencyInjection.Extensions;
6+
using Microsoft.Graph;
67

78
/// <summary>
89
/// Contains extension methods to register the <see cref="GraphSender"/> with the <c>FluentEmailServicesBuilder</c> from <c>FluentEmail.Core</c>.
@@ -31,5 +32,13 @@ public static FluentEmailServicesBuilder AddGraphSender(
3132
};
3233
return builder.AddGraphSender(options);
3334
}
35+
36+
public static FluentEmailServicesBuilder AddGraphSender(
37+
this FluentEmailServicesBuilder builder,
38+
GraphServiceClient graphClient)
39+
{
40+
builder.Services.TryAdd(ServiceDescriptor.Scoped<ISender>(_ => new GraphSender(graphClient)));
41+
return builder;
42+
}
3443
}
3544
}

β€Žsrc/FluentEmail.Graph/GraphSender.csβ€Ž

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public GraphSender(GraphSenderOptions options)
3131
this.graphClient = new (spn);
3232
}
3333

34+
public GraphSender(GraphServiceClient graphClient)
35+
{
36+
this.graphClient = graphClient;
37+
}
38+
3439
public SendResponse Send(IFluentEmail email, CancellationToken? token = null)
3540
{
3641
return this.SendAsync(email, token)

0 commit comments

Comments
Β (0)