Closed marinkobabic closed 9 years ago
Bucket is a partition that allow you to share the same StreamId on different contexts, non strictly a Tenant: you could use a bucket for a Tenant, for a Bounded Context, for Aggregate, etc
So bucket is only a logical partition, not a physical one => no additional tables per bucket. If you want a database per tenant you should create an eventstore per tenant (we work this way with the mongo engine).
It's a possible way, but the effort is huge to change the existing logic. We actually use IConnectionFactory with connectionstrings. We don't want to maintain all the connection strings and therefore switch to dynamic connections. You started already to develop in this way, but it seems without a clear concept. To have all the tenants in one database is not an option.
NEventStore doesn't have the concept of Tenant, only the concept of EventStore mapping to one database from the very beginning (we work with NES from v3). In V5 we added the Bucket to allow logical partitions, that's all. Don't understand your "You started already to develop in this way, but it seems without a clear concept", the design has always been one EventStore per db.
What is the IConnectionFactory for?
to factory a IDbConnection to the db for commands and queries. About buckets: https://github.com/NEventStore/NEventStore/issues/219
Sorry, but I don't see the point actually. What are the scenarios where you would factory the IDbConnection for the db for command and query? Just trying to understand the whole concept, before I go and change the my application architecture 1 EventStore per Db.
The IDbConnection is implemented by a custom ConnectionScope (per thread).
So you are caching in this case the connection on the thread. The supported concept is to always to connect to the same database and not to switch to different databases?
yes, always on the same db. If you need to connect to another db you should factory a new evenstore instance.
Thanks and sorry for the statement "no clear concept" :smirk:
:+1:
I seems that I do not understand the concept of the IConnectionFactory.
You have the SqlPersistenceEngine and there is a method Initialize which creates the database tables during the bootup of the application. How do you know for which tenant. IConnectionFactory is not able to figure this out without the bucketId. This can't be done during startup of the application. The IConnectionFactory.Open should get the bucketId passed like mentioned here https://github.com/NEventStore/NEventStore.Persistence.SQL/issues/2
IConnectionFactory could also have a method IsInitialized(buckedId) which must be implemented by different providers so that you know if the tables should be created or not. Another option is that you cache the IDbConnnection.ConnectionString to figure out if the initialization is required.