Can I store my active Entity framework Database Context for the request, as a static property somewhere, so it's easily fetchable from Validators, helpers etc.
**E.G set it from a global action filter onto a static class as
public static DBContext GlobalHelper.ActiveDbContextForRequest;
Does each request share these static properties though? If they do I suppose it cannot work.
Yes, static variables are shared across the entire application (over all threads). You cannot safely access these variables without synchronization from various requests (since each request is handled on a different thread).
Even if you synchronize access to these variables, there's only a single instance of the static variable so all threads will see the same value - you can't have request-specific values this way.
Static variables are global for the whole application domain by default so the answer is yes, they are shared by all requests served by it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With