-
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.
* Introduce HostBuilder Feature * Clean up
- Loading branch information
Showing
6 changed files
with
81 additions
and
10 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,16 @@ | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Featurize.AspNetCore; | ||
|
||
/// <summary> | ||
/// Describes a HostBuilder feature. | ||
/// </summary> | ||
/// <seealso cref="Featurize.IFeature" /> | ||
public interface IHostFeature : IFeature | ||
{ | ||
/// <summary> | ||
/// Allow the feature to configure the Host specific properties. | ||
/// </summary> | ||
/// <param name="hostBuilder">The Host builder.</param> | ||
void Configure(IHostBuilder hostBuilder); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Featurize.AspNetCore.Tests; | ||
public class HostBuilder_Features | ||
{ | ||
[Test] | ||
public void should_be_used() | ||
{ | ||
var feature = new SimpleHostFeature(); | ||
var builder = WebApplication.CreateBuilder(); | ||
builder.Features() | ||
.Add(feature); | ||
|
||
var app = builder.BuildWithFeatures(); | ||
|
||
feature.IsUsed.Should().BeTrue(); | ||
|
||
var act = () => app.Services.GetRequiredService<SimpleHostRegistration>(); | ||
|
||
act.Should().NotThrow<InvalidOperationException>(); | ||
|
||
} | ||
} | ||
|
||
internal class SimpleHostFeature : IHostFeature | ||
{ | ||
public bool IsUsed { get; set; } | ||
|
||
public void Configure(IHostBuilder hostBuilder) | ||
{ | ||
IsUsed = true; | ||
|
||
hostBuilder.ConfigureServices(s => | ||
{ | ||
s.AddTransient<SimpleHostRegistration>(); | ||
}); | ||
|
||
} | ||
} | ||
|
||
public class SimpleHostRegistration { } |
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