Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I've migrated my plugin from v7 to v8 of umbraco. One of the really annoying things that I had to update my repositories to inject an IScopeProvider to access the database.
public BooksRepository(IScopeProvider scopeProvider)
this.scopeProvider = scopeProvider;
Now, this was fine within my backoffice plugin as the umbraco injector would provide the scopeprovider when required.
However, I also want to use the repository in my front end razor templates - which now need a scopeProvider and there is no way to inject it.
EcBooksSection booksection = Model;
var booksRepository = new BooksRepository( scopeProvider required - WTF?);
var books = booksRepository.GetAll();
The real problem is I don't want to inject this scopeProvider - this is umbraco framework noise that I don't want to deal with in my application - why can't a static instance of the Database be available like it was in v7 that could just be used internally within the repository and not poluute my application?
Also why am i having to work with a scopeprovider - assuming its transaction related - as I don't need a transaction when I do read only operations from the database? Data access seems very badly designed in v8.
Given, if I have to work with this scopeProvider how do i make this available in my razor templates in .net framework v4.7.2?
Note: This is not .net core so the @inject directive is not available.
I decided to refactor my repository to avoid exposing IScopeProvider on my front end templates.
I now use the following to get an instance of the Database
public Book Create(Book item)
using (var scope = Current.ScopeProvider.CreateScope(autoComplete: true))
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted