ApplicationContext.GetRequiredService #3604
-
So we can't do ctor injection with Csla BOs or BusinessRules, but I see that BO instances and the rule contexts provide access to ApplicationContext, which has GetRequiredService. Is this the way to inject services we need during rule execution and custom business logic methods? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Yes, that's correct. The problem with ctor injection is that the object graph gets serialized/deserialized into different contexts - usually client and server - and so that model would require that you implement and register all the same services in both contexts. You'd be forced to have a DAL service on the client, for example. Also, you'd need to register all your domain types (business and rule classes) as DI services, which seems like an onerous process. Finally, there's a perf cost to using DI, and it would have a noticeable impact on loading large lists or other large object graphs. And on any deserialization of those graphs. Given all that, I chose to support a service locator pattern. Perhaps not ideal, but this avoids all the negatives of using ctor injection. |
Beta Was this translation helpful? Give feedback.
-
Thumbs up.
Have a nice day.
Kevin
https://rb.gy/syiuf
…________________________________
From: Rockford Lhotka ***@***.***>
Sent: Friday, December 8, 2023 11:36 AM
To: MarimerLLC/csla ***@***.***>
Cc: Subscribed ***@***.***>
Subject: Re: [MarimerLLC/csla] ApplicationContext.GetRequiredService (Discussion #3604)
Yes, that's correct.
The problem with ctor injection is that the object graph gets serialized/deserialized into different contexts - usually client and server - and so that model would require that you implement and register all the same services in both contexts. You'd be forced to have a DAL service on the client, for example.
Also, you'd need to register all your domain types (business and rule classes) as DI services, which seems like an onerous process.
Finally, there's a perf cost to using DI, and it would have a noticeable impact on loading large lists or other large object graphs. And on any deserialization of those graphs.
Given all that, I chose to support a service locator pattern. Perhaps not ideal, but this avoids all the negatives of using ctor injection.
—
Reply to this email directly, view it on GitHub<#3604 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AGJTVDQR3P6SYNOWZFRF3YLYIM6YFAVCNFSM6AAAAABAJQALG2VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TQMBRGYZDG>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
Yes, that's correct.
The problem with ctor injection is that the object graph gets serialized/deserialized into different contexts - usually client and server - and so that model would require that you implement and register all the same services in both contexts. You'd be forced to have a DAL service on the client, for example.
Also, you'd need to register all your domain types (business and rule classes) as DI services, which seems like an onerous process.
Finally, there's a perf cost to using DI, and it would have a noticeable impact on loading large lists or other large object graphs. And on any deserialization of those graphs.
Given all that, I chose to support a service locator patt…