mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-07-08 03:47:48 +02:00
common: simplify wamp logic
previously we were opening a new channel for each topic which was unnecessary
This commit is contained in:
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Streetwriters.Common.Accessors;
|
||||
using Streetwriters.Data.DbContexts;
|
||||
using Streetwriters.Data.Repositories;
|
||||
|
||||
@@ -25,6 +26,13 @@ namespace Streetwriters.Common.Extensions
|
||||
{
|
||||
public static class ServiceCollectionServiceExtensions
|
||||
{
|
||||
public static IServiceCollection AddWampServiceAccessor(this IServiceCollection services, Server server)
|
||||
{
|
||||
services.AddSingleton<WampServiceAccessor>((provider) => new WampServiceAccessor(server));
|
||||
services.AddHostedService(provider => provider.GetRequiredService<WampServiceAccessor>());
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddRepository<T>(this IServiceCollection services, string collectionName, string database) where T : class
|
||||
{
|
||||
services.AddSingleton((provider) => MongoDbContext.GetMongoCollection<T>(provider.GetRequiredService<MongoDB.Driver.IMongoClient>(), database, collectionName));
|
||||
|
||||
Reference in New Issue
Block a user