Comments (5)
Sorry to abandon my question like this, but I solved the original issue by manually requesting the db-context (via HttpContext):
public Task<IImageResolver> GetAsync(HttpContext context)
{
...
using (var dbContext = context.RequestServices.GetService<ApplicationDbContext>())
{
...
}
}
from imagesharp.web.
Hi @vyliniem
Yeah, that's a bit of a pickle for you. The reason we do that is to ensure that we do not want to instantiate complex members on each requests. For example in this Azure Blob Provider we take advantage of the singleton scoping to reuse the CloudBlobClient
. This dramatically reduces the overhead for us.
One workaround you could do for now is to use the service locator (not great but will work) inside your custom provider to return the DbContext.
In the interim I'm going to have a look to see If I can refactor this to scope the providers (cache also) to the request scope to allow more flexibility of injection but keep the performance by injecting singleton configuration types.
@sebastienros Would changing the scope upset things in Orchard or would that be ok?
from imagesharp.web.
Going scoped should never be an issue. If you need to hold state across instances the user can always create a separate instance that is registered as Singleton and resolve it in the scoped service.
from imagesharp.web.
@vyliniem just for reference you could look at this section in the .net core docs: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-2.2#call-services-from-main
You could inject the IServiceScopeFactory
into your IImageProvider
and create a scope and resolve your ApplicationDbContext inside that scope as shown in the example in the link above.
from imagesharp.web.
@sebastienros Just to clarify, are you saying I should refactor the processors to allow efficient use in a scoped lifetime?
from imagesharp.web.
Related Issues (20)
- UriAbsoluteLowerInvariantCacheKey is not backwards compatible HOT 3
- DirectoryNotFoundException: ... \wwwroot\ for Azure blob storage provider HOT 4
- How to prevent rotation based on Exif Orientation HOT 1
- WebP images don't auto orient based on EXIF metadata HOT 16
- AWS S3 Transfert Acceleration HOT 1
- v1.0.5 unsupported format prevents all processing HOT 2
- Add Custom Parameter to the request url for caching HOT 2
- 2.0.0 Breaks on filenames with special characters HOT 2
- Middleware is very susceptible to unreasonable processing commands HOT 1
- ImageSharp Web does not appear to handle rotation during format change to WEBP HOT 4
- Unable to access SixLabors.ImageSharp.Web.Caching.Azure namespace HOT 2
- Link to license in GitHub README returns 404
- OnBeforeSaveAsync called only when there are available Commands which is not correct in some scenarios
- Azure middleware trows an exception in 3.0+ version HOT 16
- Image caching does not differentiate between different query strings HOT 1
- Confusing 500 error with width (or height) querystring - Umbraco thumbnails HOT 2
- Major CPU performance decrease with ImageSharp.Web 3 HOT 20
- "Sending image. Request uri" log Should be debug not information HOT 2
- Formatting an image to webp is losing some of the transparency in the image
- Open Snyk Issue with high severity for several months HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imagesharp.web.