Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having a Default DbContextFactory #34

Open
reader-man opened this issue Jan 4, 2016 · 0 comments
Open

Having a Default DbContextFactory #34

reader-man opened this issue Jan 4, 2016 · 0 comments

Comments

@reader-man
Copy link

Maybe it would be nice to have a Default DbContextFactory, that gives the client the possibility to set the connection string for projects that have multiple DBs.

namespace Mehdime.Entity
{
    public class DbContextFactoryDefault : IDbContextFactory
    {
        string _connection;
        public DbContextFactoryDefault(string connection_)
        {
            _connection = connection_;
        }

        public TDbContext CreateDbContext<TDbContext>() where TDbContext : DbContext
        {
            object[] arguments = new object[1] { (object)_connection };

            return (TDbContext)Activator.CreateInstance(typeof(TDbContext), arguments);
        }
    }
}

Use:

Dim dbContextScopeFactory = New DbContextScopeFactory(New DbContextFactoryDefault("testCon"))
Dim ambientDbContextLocator = New AmbientDbContextLocator()

Regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant