public void UpdateClient(string clientName, ICallistoClient client) { string key = ValidateAndParseRegistryKey(clientName); if (!_clients.TryUpdate(key, client)) { throw new CallistoException($"The application was unable to update the client '{clientName}.'"); } }
public void AddClient(string clientName, ICallistoClient client) { Check.ThrowIfNull(client, nameof(ICallistoClient), new CallistoException($"A null instance of a '{nameof(ICallistoClient)}' is not acceptable.")); Check.ThrowIfNullOrEmpty(clientName, nameof(clientName), new CallistoException("To add a client to the registry, you must provide a key.")); if (!_clients.TryAdd(clientName.ToUpperInvariant(), client)) { throw new CallistoException($"The application was unable to add the client '{clientName}' into the registry."); } }
public ICallistoClientConfigurator RegisterClient(string clientName, ICallistoClient client, Action <ICallistoCollectionConfigurator> configureCollections) { Check.ThrowIfNullOrEmpty(clientName, nameof(clientName), new CallistoException("Please provide the name of the client that should be registered.")); Check.ThrowIfNull(client, nameof(ICallistoClient), new CallistoException("Please provide a valid instance of a 'ICallistoClient'")); _builder.AddBuildAction(new BuildAction($"Registering Callisto client with name: {clientName}") { Action = provider => { var registry = provider.GetRequiredService <ICallistoClientRegistry>(); registry.AddClient(clientName, client); } }); configureCollections?.Invoke(new CallistoCollectionConfigurator(_builder, clientName)); return(this); }
/// <summary> /// Registers the collection context. /// You only need to call this method when theres no need for a repository to be registered. /// </summary> /// <param name="database"></param> /// <param name="collection"></param> /// <param name="lifetime"></param> /// <typeparam name="TDocumentRoot"></typeparam> /// <returns></returns> public ICallistoCollectionConfigurator ConfigureCollectionContext <TDocumentRoot>(string database, string collection, ServiceLifetime lifetime) where TDocumentRoot : class, IDocumentRoot { _solariBuilder.Services.Add(ServiceDescriptor.Describe(typeof(ICallistoCollectionContext <TDocumentRoot>), provider => { Check.ThrowIfNullOrEmpty(collection, nameof(collection), new CallistoException("Collection name is required to create a ICollectionContext<T>")); Check.ThrowIfNullOrEmpty(database, nameof(database), new CallistoException("Database name is required to create a ICollectionContext<T>")); var registry = provider.GetRequiredService <ICallistoClientRegistry>(); ICallistoClient callistoClient = registry.GetClient(_clientName); IMongoDatabase mongoDatabase = callistoClient.MongoClient.GetDatabase(database); IMongoCollection <TDocumentRoot> mongoCollection = mongoDatabase.GetCollection <TDocumentRoot>(collection); return(new CallistoCollectionContext <TDocumentRoot>(callistoClient, mongoCollection, mongoDatabase)); }, lifetime)); return(this); }
public CallistoCollectionContext(ICallistoClient callistoClient, IMongoCollection <T> collection, IMongoDatabase database) { CallistoClient = callistoClient; Collection = collection; Database = database; }