Injecting dependencies after the object has returned from the server #3804
Replies: 8 comments 36 replies
-
What dependencies are you hoping to access on the client? |
Beta Was this translation helpful? Give feedback.
-
To name a few, the DataPortalFactory and some Azure utilities like a KeyVault encryption/decryption utility class. Plus any connection manager we want to create. |
Beta Was this translation helpful? Give feedback.
-
Also, on the DataPortalFactory, we're doing it at a base level where we don't have the ability to work with a generic as a parameter, so we're using the DataPortalFactory. While the initial call may be from the ViewModel, it may be very possible that a child list is fetched on-demand AFTER the BO has been returned from Save or even the original fetch. Does that make sense?
Given that we now need to do another fetch from within the BO, how would you expect us to do so without the dependency? |
Beta Was this translation helpful? Give feedback.
-
I have a BusinessBase object that has a child BusinessBindingListBase registered child object. When the BO is bound to the WinForms UI, after Fetch/Save, our DataGridView is bound to the child list object. So i guess you're saying that since each BO/BO List has a reference to ApplicationContext, any necessary dependencies should be requested through ApplicationContext.GetRequiredService? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Here was my concern about this section. I'm fine following this for getting the IChildDataPortal specifically, but in a general sense, using a Service Locator is an anti-pattern: https://blog.ploeh.dk/2014/05/15/service-locator-violates-solid/#:~:text=The%20Service%20Locator%20anti-pattern%20violates%20the%20ISP%2C%20and%20thus,is%20that%20it%20violates%20encapsulation. Given that, I was thinking that what should PROBABLY (?) happen is that upon return from the server, when you do the "if (IUsesApplicationContext)', since you're going through each object anyway, the dependencies should be reinjected then. |
Beta Was this translation helpful? Give feedback.
-
So maybe that's where I'm a little lost. Why can we not do ctor injection? I'm not entirely sure why that's off the table. Regardless though, I would think a method similar in signature to fetch/create might do what we would need here. This obviously couldn't be an override, but it gives you the idea. Something that's called automatically during deserialization or even during Initialize, allowing the dependencies to be set as soon as possible. |
Beta Was this translation helpful? Give feedback.
-
I think in principlel, it would be this. Basically use it if you already have it somehow and only get if it it's null. |
Beta Was this translation helpful? Give feedback.
-
Hi. Question. Right now, like the documentation shows, we’re defining the [Inject] attribute on the DP methods like usual. However, these business objects are sent to the server for save, and when the object is returned, obviously my dependencies are null.
How am I supposed to “reinject” them on the returned object given that CSLA object constructors can’t have parameters?
Beta Was this translation helpful? Give feedback.
All reactions