-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support config from appsettings * . * make BaseEmailService.Send abstract (implemented by sink) --------- Co-authored-by: Simone Ronzoni <[email protected]>
- Loading branch information
Showing
49 changed files
with
1,072 additions
and
421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using fbognini.Notifications; | ||
using fbognini.Notifications.Sinks.Email; | ||
using fbognini.Notifications.Source.AppSettings; | ||
using fbognini.Notifications.WorkerSample; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
IHost host = Host.CreateDefaultBuilder(args) | ||
.ConfigureServices((ctx, services) => | ||
{ | ||
services.AddHostedService<Worker>(); | ||
services.AddNotifications() | ||
.AddEmailService("SUPPORT") | ||
.FromAppSettings(ctx.Configuration); | ||
}) | ||
.Build(); | ||
|
||
host.Run(); |
11 changes: 11 additions & 0 deletions
11
examples/fbognini.Notifications.WorkerSample/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"profiles": { | ||
"fbognini.Notifications.WorkerSample": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"environmentVariables": { | ||
"DOTNET_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using fbognini.Notifications.Interfaces; | ||
|
||
namespace fbognini.Notifications.WorkerSample | ||
{ | ||
public class Worker : BackgroundService | ||
{ | ||
private readonly ILogger<Worker> _logger; | ||
private readonly IEmailService emailService; | ||
|
||
public Worker(ILogger<Worker> logger, IEmailService emailService) | ||
{ | ||
_logger = logger; | ||
this.emailService = emailService; | ||
} | ||
|
||
protected override async Task ExecuteAsync(CancellationToken stoppingToken) | ||
{ | ||
while (!stoppingToken.IsCancellationRequested) | ||
{ | ||
await emailService.SendAsync("[email protected]", "test", "body", cancellationToken: stoppingToken); | ||
|
||
_logger.LogInformation("Email sent at: {time}", DateTimeOffset.Now); | ||
await Task.Delay(1000, stoppingToken); | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
examples/fbognini.Notifications.WorkerSample/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
examples/fbognini.Notifications.WorkerSample/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
}, | ||
"fbognini.Notifications": { | ||
"EmailConfigs": [ | ||
{ | ||
"Id": "SUPPORT", | ||
"UseSsl": false, | ||
"SmtpHost": "localhost", | ||
"SmtpPort": 25, | ||
"UseAuthentication": false, | ||
"SmtpUsername": "", | ||
"SmtpPassword": "", | ||
"FromEmail": "[email protected]" | ||
} | ||
] | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
examples/fbognini.Notifications.WorkerSample/fbognini.Notifications.WorkerSample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Worker"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\fbognini.Notifications.Sinks.Email\fbognini.Notifications.Sinks.Email.csproj" /> | ||
<ProjectReference Include="..\..\src\fbognini.Notifications.Source.AppSettings\fbognini.Notifications.Source.AppSettings.csproj" /> | ||
<ProjectReference Include="..\..\src\fbognini.Notifications\fbognini.Notifications.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using fbognini.Notifications.Interfaces; | ||
using fbognini.Notifications.Services; | ||
using fbognini.Notifications.Sinks.MTarget.Sdk; | ||
using fbognini.Notifications.Sinks.MTarget.Services; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace fbognini.Notifications.Sinks.MTarget | ||
{ | ||
public class MTargetSinkBuilder : SinkBuilder | ||
{ | ||
internal MTargetSinkBuilder(IServiceCollection services) | ||
: base(services) | ||
{ | ||
} | ||
|
||
internal MTargetSinkBuilder AddMTargetService() | ||
{ | ||
Services | ||
.AddTransient<ISmsService, MTargetSmsService>(); | ||
|
||
return this; | ||
} | ||
|
||
internal MTargetSinkBuilder AddMTargetService(string id) | ||
{ | ||
Services.AddHttpClient<IMTargetService, MTargetService>((sp, cl) => | ||
{ | ||
}); | ||
|
||
Services | ||
.AddTransient<ISmsService, MTargetSmsService>((provider) => new MTargetSmsService(id, provider.GetRequiredService<ISettingsProvider>(), provider.GetRequiredService<IMTargetService>())); | ||
return this; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
src/fbognini.Notifications.MTarget/Services/MTargetSmsService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,19 @@ | ||
using fbognini.Notifications.Interfaces; | ||
using fbognini.Notifications.MTarget.Sdk; | ||
using fbognini.Notifications.MTarget.Services; | ||
using fbognini.Notifications.Services; | ||
using fbognini.Notifications.Settings; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System; | ||
using fbognini.Notifications.Services; | ||
|
||
namespace fbognini.Notifications.MTarget | ||
namespace fbognini.Notifications.Sinks.MTarget | ||
{ | ||
public static class Startup | ||
{ | ||
public static NotificationsBuilder AddMTargetService(this NotificationsBuilder builder) | ||
public static MTargetSinkBuilder AddMTargetService(this SinkBuilder builder) | ||
{ | ||
builder.Services | ||
.AddTransient<ISmsService, MTargetSmsService>(); | ||
|
||
return builder; | ||
return new MTargetSinkBuilder(builder.Services) | ||
.AddMTargetService(); | ||
} | ||
|
||
public static NotificationsBuilder AddMTargetService(this NotificationsBuilder builder, string id) | ||
public static MTargetSinkBuilder AddMTargetService(this SinkBuilder builder, string id) | ||
{ | ||
builder.Services.AddHttpClient<IMTargetService, MTargetService>((sp, cl) => | ||
{ | ||
}); | ||
|
||
builder.Services | ||
.AddTransient<ISmsService, MTargetSmsService>((provider) => new MTargetSmsService(id, provider.GetRequiredService<DatabaseSettings>(), provider.GetRequiredService<IMTargetService>())); | ||
|
||
return builder; | ||
return new MTargetSinkBuilder(builder.Services) | ||
.AddMTargetService(id); | ||
} | ||
} | ||
} |
33 changes: 0 additions & 33 deletions
33
src/fbognini.Notifications.MTarget/fbognini.Notifications.MTarget.csproj
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
src/fbognini.Notifications.MTarget/fbognini.Notifications.Sinks.MTarget.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> | ||
<Version>2.0</Version> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.ServiceModel.Duplex" Version="4.10.0" /> | ||
<PackageReference Include="System.ServiceModel.Http" Version="4.10.0" /> | ||
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.10.0" /> | ||
<PackageReference Include="System.ServiceModel.Security" Version="4.10.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\fbognini.Notifications\fbognini.Notifications.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="fbognini.Sdk" Version="2.2.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'"> | ||
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'"> | ||
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.