You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 24, 2026. It is now read-only.
Next, create the UnitOfWork class. This handles the connection to the database. I normally create this in the Repository folder of my class library project.
publicclassUnitOfWork:UnitOfWorkBase{publicUnitOfWork(IConfigurationconfig){DbAdapter=newMySqlDbAdapter(config.GetConnectionString("default"));// ^ Change the DbAdapter based on the type of database you are connecting to}// Stores the repositories that have already been initializedprivatereadonlyDictionary<Type,object>repos=newDictionary<Type,object>();publicTRepoGetRepo<TRepo>()whereTRepo:IDbRepository{Typetype=typeof(TRepo);if(!repos.ContainsKey(type))repos[type]=Activator.CreateInstance(type,this);return(TRepo)repos[type];}}
Important
The UnitOfWork should then be added to your dependency injection services as a scoped service so it can be easily access and automatically disposed of when a request is finished.