Ejemplo n.º 1
0
 /// <summary>
 /// Creates the MongoDB connection with the specified database name and whether to use a single node replica set
 /// </summary>
 /// <param name="dbName">Name of the database</param>
 /// <param name="replSet">Use a single node replicate set. Defaults to false</param>
 protected static void CreateDBConnection(string dbName, bool replSet = false)
 {
     database_name     = dbName;
     runner            = MongoDbRunner.Start(singleNodeReplSet: replSet);
     connection_string = runner.ConnectionString;
     client            = new MongoClient(connection_string);
     database          = client.GetDatabase(database_name);
     configuration_for_read_model_repository = new Dolittle.ReadModels.MongoDB.Configuration(new FakeIConfigurationFor(connection_string, database_name));
 }
Ejemplo n.º 2
0
        public IEnumerable <IComponentRegistration> RegistrationsFor(Service service,
                                                                     Func <Service, IEnumerable <IComponentRegistration> > registrationAccessor)
        {
            var serviceWithType = service as IServiceWithType;

            if (serviceWithType == null || serviceWithType.ServiceType != typeof(Dolittle.ReadModels.MongoDB.Configuration))
            {
                return(Enumerable.Empty <IComponentRegistration>());
            }

            var registration = new ComponentRegistration(
                Guid.NewGuid(),
                new DelegateActivator(serviceWithType.ServiceType, (c, p) =>
            {
                var connectionStrings = c.Resolve <IOptions <ConnectionStringsOptions> >().Value;
                var connectionString  =
                    connectionStrings.ConnectionStrings.SingleOrDefault(t =>
                                                                        t.Type == ConnectionStringType.MongoDB);
                if (connectionString == null)
                {
                    throw new MissingConnectionStringForDatabaseType(ConnectionStringType.MongoDB);
                }

                var configuration = new Dolittle.ReadModels.MongoDB.Configuration
                {
                    Url             = connectionString.Value,
                    UseSSL          = false,
                    DefaultDatabase = connectionString.Database
                };
                return(configuration);
            }),
                new CurrentScopeLifetime(),
                InstanceSharing.Shared,
                InstanceOwnership.OwnedByLifetimeScope,
                new[] { service },
                new Dictionary <string, object>()
                );

            return(new[] { registration });
        }