Skip to content

Commit

Permalink
Update AddMongoSchemaRegistry to accept an IConfiguration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Sneed committed Jan 31, 2022
1 parent ffbdfed commit a0fda1d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.1.0</Version>
<Version>1.2.0-beta1</Version>
<Authors>Tony Sneed</Authors>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>eda-logo.jpeg</PackageIcon>
Expand All @@ -12,7 +12,7 @@
<RepositoryUrl>https://github.com/event-driven-dotnet/EventDriven.SchemaRegistry.Mongo.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>schema-registry event-driven event-driven-architecture</PackageTags>
<PackageReleaseNotes>https://github.com/event-driven-dotnet/EventDriven.SchemaRegistry.Mongo/releases/tag/v1.1.0</PackageReleaseNotes>
<PackageReleaseNotes>https://github.com/event-driven-dotnet/EventDriven.SchemaRegistry.Mongo/releases/tag/v1.2.0-beta1</PackageReleaseNotes>
<PackageId>EventDriven.SchemaRegistry.Mongo</PackageId>
<RootNamespace>EventDriven.SchemaRegistry.Mongo</RootNamespace>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
Expand All @@ -21,11 +21,12 @@
<ItemGroup>
<None Include="..\..\images\eda-logo.jpeg">
<Pack>True</Pack>
<PackagePath></PackagePath>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="EventDriven.DependencyInjection.URF.Mongo" Version="1.1.0-beta3" />
<PackageReference Include="EventDriven.SchemaRegistry.Abstractions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageReference Include="MongoDB.Driver" Version="2.14.1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using EventDriven.DependencyInjection.URF.Mongo;

namespace EventDriven.SchemaRegistry.Mongo
{
/// <summary>
/// Mongo state Store options.
/// </summary>
public class MongoStateStoreOptions
public class MongoStateStoreOptions : IMongoDbSettings
{
/// <summary>
/// Mongo connection string.
Expand All @@ -18,6 +20,6 @@ public class MongoStateStoreOptions
/// <summary>
/// Mongo schemas collection name.
/// </summary>
public string SchemasCollectionName { get; set; } = "schemas";
public string CollectionName { get; set; } = "schemas";
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using EventDriven.DependencyInjection.URF.Mongo;
using EventDriven.SchemaRegistry.Abstractions;
using EventDriven.SchemaRegistry.Mongo;
using MongoDB.Bson.Serialization.Conventions;
using Microsoft.Extensions.Configuration;
using MongoDB.Driver;
using URF.Core.Abstractions;
using URF.Core.Mongo;
Expand All @@ -14,6 +15,24 @@ namespace Microsoft.Extensions.DependencyInjection
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds MongoSchemaRegistry services to the provided <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" />.
/// </summary>
/// <param name="services">The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /></param>
/// <param name="configuration">The application's <see cref="IConfiguration"/>.</param>
/// <returns>The original <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" />.</returns>
public static IServiceCollection AddMongoSchemaRegistry(this IServiceCollection services, IConfiguration configuration)
{
// Add MongoDb settings
services.AddMongoDbSettings<MongoStateStoreOptions, MongoSchema>(configuration);

// Register services
services.AddSingleton<ISchemaRegistry, MongoSchemaRegistry>();
services.AddSingleton<IDocumentRepository<MongoSchema>, DocumentRepository<MongoSchema>>();

return services;
}

/// <summary>
/// Adds MongoSchemaRegistry services to the provided <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" />.
/// </summary>
Expand All @@ -32,21 +51,14 @@ public static IServiceCollection AddMongoSchemaRegistry(this IServiceCollection
services.AddSingleton(sp =>
{
var context = new MongoSchemaRegistryDbContext(new MongoClient(schemaOptions.ConnectionString),
schemaOptions.DatabaseName, schemaOptions.SchemasCollectionName);
schemaOptions.DatabaseName, schemaOptions.CollectionName);
return context.MongoSchemas;
});

// Register services
services.AddSingleton<ISchemaRegistry, MongoSchemaRegistry>();
services.AddSingleton<IDocumentRepository<MongoSchema>, DocumentRepository<MongoSchema>>();

// Register caml case convention
var conventionPack = new ConventionPack
{
new CamelCaseElementNameConvention()
};
ConventionRegistry.Register("camlCase", conventionPack, _ => true);

return services;
}
}
Expand Down

0 comments on commit a0fda1d

Please sign in to comment.