Пример #1
0
        static void ConfigureDefaultMongoDbIfNecessary(MessageBusConfigurator cfg)
        {
            string connstr, collection;

            if (!Util.ParseMongoEndpoint(cfg.Endpoint, out connstr, out collection))
            {
                throw new Exception("Invalid mongo connection string: " + cfg.Endpoint);
            }
            var dic = new Dictionary <string, string>();

            foreach (var cs in cfg.GetConnectionStrings())
            {
                if (cs.Name == null || dic.ContainsKey(cs.Name))
                {
                    continue;
                }
                dic[cs.Name] = cs.ConnectionString;
            }
            var cstr = Util.GetMongoConnectionStringForEndpoint(cfg.Endpoint, dic);

            cfg.CustomizeContainer(wc =>
            {
                if (!MessageBusConfigurator.IsServiceRegistered(wc, typeof(MongoDatabase)))
                {
                    wc.Register(Component.For <MongoDatabase>()
                                .Instance(MongoDatabase.Create(cstr)));
                }
            });
        }
Пример #2
0
 public static MessageBusConfigurator UseMongoDbSubscriptions(this MessageBusConfigurator cfg)
 {
     ConfigureDefaultMongoDbIfNecessary(cfg);
     cfg.CustomizeContainer(wc =>
     {
         if (!MessageBusConfigurator.IsServiceRegistered(wc, typeof(ISubscriptionService)))
         {
             wc.Register(Component.For <ISubscriptionService>().ImplementedBy <MongoDbSubscriptionService>()
                         .DependsOn(new
             {
                 CollectionName       = "NG_Subscriptions",
                 SubscriptionLifetime = cfg.SubscriptionLifetime
             }).LifeStyle.Singleton);
         }
     });
     return(cfg);
 }