-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added an interface with factory - included ef core provider - included json provider - update the test programs to utilize the repository approach
- Loading branch information
Dries Verbeke
committed
Jul 22, 2022
1 parent
3ebe5d5
commit c614f7a
Showing
26 changed files
with
674 additions
and
618 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
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,45 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using InstantAPIs.Repositories; | ||
|
||
namespace InstantAPIs; | ||
namespace Microsoft.Extensions.DependencyInjection; | ||
|
||
public static class InstantAPIsServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddInstantAPIs(this IServiceCollection services, Action<InstantAPIsOptions>? setupAction = null) | ||
{ | ||
var options = new InstantAPIsOptions(); | ||
|
||
// Get the service options | ||
setupAction?.Invoke(options); | ||
|
||
if (options.EnableSwagger == null) | ||
{ | ||
options.EnableSwagger = EnableSwagger.DevelopmentOnly; | ||
} | ||
|
||
// Add and configure Swagger services if it is enabled | ||
if (options.EnableSwagger != EnableSwagger.None) | ||
{ | ||
services.AddEndpointsApiExplorer(); | ||
services.AddSwaggerGen(options.Swagger); | ||
} | ||
|
||
// Register the required options so that it can be accessed by InstantAPIs middleware | ||
services.Configure<InstantAPIsOptions>(config => | ||
{ | ||
config.EnableSwagger = options.EnableSwagger; | ||
}); | ||
|
||
return services; | ||
} | ||
public static IServiceCollection AddInstantAPIs(this IServiceCollection services, Action<InstantAPIsOptions>? setupAction = null) | ||
{ | ||
var options = new InstantAPIsOptions(); | ||
|
||
// Get the service options | ||
setupAction?.Invoke(options); | ||
|
||
if (options.EnableSwagger == null) | ||
{ | ||
options.EnableSwagger = EnableSwagger.DevelopmentOnly; | ||
} | ||
|
||
// Add and configure Swagger services if it is enabled | ||
if (options.EnableSwagger != EnableSwagger.None) | ||
{ | ||
services.AddEndpointsApiExplorer(); | ||
services.AddSwaggerGen(options.Swagger); | ||
} | ||
|
||
// Register the required options so that it can be accessed by InstantAPIs middleware | ||
services.Configure<InstantAPIsOptions>(config => | ||
{ | ||
config.EnableSwagger = options.EnableSwagger; | ||
}); | ||
|
||
services.AddSingleton(typeof(IRepositoryHelperFactory<,,,>), typeof(RepositoryHelperFactory<,,,>)); | ||
services.AddSingleton(typeof(IContextHelper<>), typeof(ContextHelper<>)); | ||
|
||
// ef core specific | ||
services.AddSingleton<IRepositoryHelperFactory, InstantAPIs.Repositories.EntityFrameworkCore.RepositoryHelperFactory>(); | ||
services.AddSingleton<IContextHelper, InstantAPIs.Repositories.EntityFrameworkCore.ContextHelper>(); | ||
|
||
// json specific | ||
services.AddSingleton<IRepositoryHelperFactory, InstantAPIs.Repositories.Json.RepositoryHelperFactory>(); | ||
services.AddSingleton<IContextHelper, InstantAPIs.Repositories.Json.ContextHelper>(); | ||
|
||
return services; | ||
} | ||
} |
Oops, something went wrong.