Correct setup of dependency injection for Windows Service & asp.net framework? #1983
Replies: 3 comments 42 replies
-
CSLA doesn't manage the DI container in any way. It just uses the DI container. In other words, whether the DI container is disposed or not is 100% up to the container (or you?). |
Beta Was this translation helpful? Give feedback.
-
@ajohnstone-ks You'd need to be doing something similar to that to ensure an IServiceScope scope was created per request. You'd then need to call the csla application context extension method for setting the current scoped service provider to your ServiceScopes IServiceProvider at the start of the request - if this isn't set, csla will use the default IServiceProvider which I can see you are setting but this won't be created / disposed per request. |
Beta Was this translation helpful? Give feedback.
-
Hi,
When your remote data portal runs locally, it means the dependencies CSLA
will want to inject are from some scope within your existing application.
Due to this, your application has more say in how it arranges its DI scopes
- I dont think CSLA should take control of creating seperate DI scopes
within your local application - one per local DP operation for example.
On a remote server, serving requests from multiple clients, there is a
natural "per request" scope for each client and so this makes sense- and
you configure your services lifetimes with this model in mind.
When there is no remote server however, and the DP runs locally in your own
application - your application needs to supply scopes to csla. For example
perhaps in your Windows forms application, you want each new window to run
in its own scope - so that when the window closes, any dependencies
injected into will be disposed (db context etc). Perhaps you have some
background jobs - each of those jobs can have its own scope so anything
activated within the job will used dependencies scoped to that job and they
will all be cleaned up when the job finishes. You tell csla what scope its
operating within, and that impacts which dependencies will be consumed by
Csla. This allows your application to control where it creates scopes so
you can create scopes that last longer than a single DP invocation..
Therefore with the windows forms example, you'd need to figure out:
Do you want to use scopes? If not, csla can use your top level
IServiveProvider - but make sure you don't register any IDisposable
services because they won't ever be disposed.
For your background threads example, if each thread needs its own instances
if dependencies then consider creating a scope per thread and having that
thread do any DI from that scope.
Hope this helps
…On Mon, 14 Dec 2020, 19:43 ajohnstone-ks, ***@***.***> wrote:
@rockfordlhotka <https://github.com/rockfordlhotka> So I think I have
some things to try for the remote data portal hosted in asp.net
framework, but I'm still not clear on where I would need to look to fix
things in the Windows service.
Basically the service spins up a bunch of threads, and each of those
threads will use a business object (typically a command) to do some work.
This is all done in local data portal mode, so client & server are the same
physical tier. I think this could be an issue on the desktop client app as
well, but AFAIK we don't actually create an disposables in any logical
server side code on the client.
It seems like something would need to happen soon after the transition to
the logical server side code is made, but before Csla actually invokes the
Create/Insert/Update/Delete/Fetch methods, and then dispose the scope
before the transition back to the logical client side code.
Any tips on where to start looking for this?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1983 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAYHROGVOE4BHV5KW7KF53TSUZTGDANCNFSM4U27FNYA>
.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm a bit unclear on the proper configuration of Csla & the service provider when using the server data portal methods.
Currently we are doing this to set it up, both in a Windows Server application (which uses the Local data portal only) and on our Asp.net framework application which hosts the remote data portal our desktop clients use.
I think we are seeing some connection leaks though, as I've had to restart the Windows Service as it was getting timeouts getting a SqlConnection from the pool. I think our remote data portal application server has the same issue as well, as things slow down over time and we need to restart it.
I think the issues crop up slowly over time as we've only just started converting things from the old way we got a connection to using
[Inject]
for our dependencies, but I'd like to verify that we are setting things up correctly so that, in the end, theUnityContainer
which is created by the ServiceProvider is being deposed after every server side data portal operation.Is the above correct, or am I missing something?
Beta Was this translation helpful? Give feedback.
All reactions