Skip to content

Commit

Permalink
Add SetContextFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
hbulens committed Mar 24, 2023
1 parent 96e9324 commit 28fecf9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PackageId>Dime.Repositories.Sql.EntityFramework</PackageId>
<PackageTags>Entity Framework;Repository;SQL</PackageTags>
<PackageIconUrl>https://cdn.dime-software.com/dime-software/logo-shape.png</PackageIconUrl>
<Version>2.0.0.0-alpha.45</Version>
<Version>2.0.0.0-alpha.47</Version>
<Description>Implementation of the repository pattern with Microsoft SQL using Entity Framework Core</Description>
<Copyright>Copyright © 2022</Copyright>
<PackageProjectUrl>https://github.com/dimesoftware/repository</PackageProjectUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Dime.Repositories
{
[ExcludeFromCodeCoverage]
public class EfRepositoryFactory<TContext> : IRepositoryFactory<RepositoryConfiguration>
public class EfRepositoryFactory<TContext> : IEfRepositoryFactory<TContext, RepositoryConfiguration>
where TContext : DbContext
{
public EfRepositoryFactory(IDbContextFactory<TContext> contextFactory)
Expand All @@ -18,13 +18,18 @@ public EfRepositoryFactory(IDbContextFactory<TContext> contextFactory, Repositor
RepositoryConfiguration = repositoryConfiguration;
}

private IDbContextFactory<TContext> ContextFactory { get; }
private IDbContextFactory<TContext> ContextFactory { get; set; }
private RepositoryConfiguration RepositoryConfiguration { get; set; }

public virtual IRepository<TEntity> Create<TEntity>() where TEntity : class, new()
=> Create<TEntity>(RepositoryConfiguration);

public virtual IRepository<TEntity> Create<TEntity>(RepositoryConfiguration opts) where TEntity : class, new()
=> new EfRepository<TEntity, TContext>(ContextFactory, opts);

public void SetContextFactory(IDbContextFactory<TContext> contextFactory)
{
ContextFactory = contextFactory;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Microsoft.EntityFrameworkCore;

namespace Dime.Repositories
{
public interface IEfRepositoryFactory<TContext, in TOpts> : IRepositoryFactory<RepositoryConfiguration> where TContext : DbContext
{
void SetContextFactory(IDbContextFactory<TContext> contextFactory);
}
}

0 comments on commit 28fecf9

Please sign in to comment.