Ejemplo n.º 1
0
        public static void UseMongoPersistence(
            this BewitPayloadContext context,
            IConfiguration configuration)
        {
            MongoNonceOptions options = configuration
                                        .GetSection("Bewit:Mongo")
                                        .Get <MongoNonceOptions>();

            context.UseMongoPersistence(options);
        }
Ejemplo n.º 2
0
        public MongoNonceRepository(IMongoDatabase database, MongoNonceOptions options)
        {
            if (database == null)
            {
                throw new ArgumentNullException(nameof(database));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _collection = database.GetCollection <Token>(options.CollectionName);
        }
Ejemplo n.º 3
0
        internal static void Validate(this MongoNonceOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.ConnectionString))
            {
                throw new ArgumentException(
                          "Value cannot be null or whitespace.",
                          nameof(ConnectionString));
            }

            if (string.IsNullOrWhiteSpace(options.DatabaseName))
            {
                throw new ArgumentException(
                          "Value cannot be null or whitespace.",
                          nameof(options.DatabaseName));
            }
        }
Ejemplo n.º 4
0
        public static void UseMongoPersistence(
            this BewitPayloadContext context,
            MongoNonceOptions options)
        {
            options.Validate();

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.SetRepository(() =>
            {
                var client = new MongoClient(options.ConnectionString);
                IMongoDatabase database = client.GetDatabase(options.DatabaseName);
                return(new MongoNonceRepository(database, options));
            });
        }