-
Good day guys. I haven't worked on a QPF PRISM project for a while until now. And the memory is a little slow :) I have my Unit of Work implementation wit the related repositories. I am just not sure how get this configured and injected correctly. This is what the Unit of Work class looks like public class UnitOfWork : IUnitOfWork
And here is the constructor for the Db Context
Now in normal circumstances like in a web api you would call services.AddDbContext.... or something like that where you can configure the db context with its connection string etc. in the startup class. I am using a .NET 6 WPF project and class libraries in this solution. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
the var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
builder.UseSqlServer("...");
containerRegistry.RegisterInstance(builder.Options);
containerRegistry.Register<ApplicationDbContext>(); |
Beta Was this translation helpful? Give feedback.
the
services.AddDbContext<TContext>(...)
extension just adds a little syntax sugar around registering the DbContext. It's not really magic though and you should be able to view the source from Visual Studio. By default it will register the DbContext as a Scoped service which isn't really relevant for your WPF app... you would want to look at either registering it as a singleton or possibly a Transient if you see errors with one process trying to query the database concurrantly with another process in your app. There are a few ways you could do this but you might look at something like: