1. Juan Alejandro Lam López
  2. SnapObjects
  3. Saturday, 22 June 2019 05:27 AM UTC

Hi all.
I have a server with more than 500 databases with the same structure and I would like to know how I can implement a connection factory with SnapObjects. And how to connect dynamically to each one these.

 

Regards

Accepted Answer
Juan Alejandro Lam López Accepted Answer Pending Moderation
  1. Monday, 8 July 2019 04:52 AM UTC
  2. SnapObjects
  3. # Permalink

Hi Logan Liu.


Thanks for the help, I was able to replicate and develop a new example and I am uploading it to the Community.

Regards

Attachments (1)
Comment
There are no comments made yet.
Logan Liu @Appeon Accepted Answer Pending Moderation
  1. Monday, 24 June 2019 07:35 AM UTC
  2. SnapObjects
  3. # 1

Hi Juan,

 

The following points may be helpful for creating your DataContext factory:

1. Pass in the connection string to construct the DataContextOption object.

E.g.:

new SqlServerDataContextOptions(connectionString)

2. Pass in DataContextOptions object to construct the DataContext.

E.g.:

    public class SampleDataContext : SqlServerDataContext
    {
        public SampleDataContext(IDataContextOptions options)        
            : base(options)
        {
        }
    }

3. Create a DataContextFactory class which can create corresponding DataContext object based on the key of the connection string. Depending on your business logic, you might want to consider the database type in the DataContextFactory class.

4. Inject the DataContextFactory into the DI framework (note the lifetime), then receive and use it in each service to get DataContext.

 

Regards,

Logan

Attachments (1)
Comment
There are no comments made yet.
Juan Alejandro Lam López Accepted Answer Pending Moderation
  1. Sunday, 23 June 2019 18:13 PM UTC
  2. SnapObjects
  3. # 2

You could help me to implement something similar to this

https://dzone.com/articles/dynamic-connection-string-in-net-core

or something similar that helps me manage multiple connections to different databases and change them in execution time.

 

 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.