MarimerLLC / cslaforum

Discussion forum for CSLA .NET
https://cslanet.com
Other
31 stars 6 forks source link

Dataportal share between client / server side #161

Open mvklingeren opened 8 years ago

mvklingeren commented 8 years ago

I would like to specify in my application what dependency injection should be used on the server side of the dataportal, using a composite pattern.

Problem is, how do i get my dataportal to take 'an object' from my client to be able to use that on the server?

additional: i'm aware of the fact that i cannot transfer references from client to server > it's just about values / type info.

rockfordlhotka commented 8 years ago

It is important to understand first, that the DI/IoC pattern doesn't take into account distributed computing. The pattern assumes all your code is running in the same memory space (AppDomain in .NET terms).

@JasonBock wrote some good material on using DI within the server-side DataPortal: http://magenic.com/Blog/Post/43/Abstractions-in-CSLA

You can also use DI on the client as you desire.

You generally can not use constructor injection because we are dealing with serializable objects that move outside of the AppDomain (a weak area for DI/IoC), so you must use property injection. This is true on the client and server.

You also can inject business objects (not infrastructure objects like db connections, UI elements, etc. - only business layer objects) into your object graph as long as:

  1. You make the injected object serializable
  2. You maintain the reference to the injected object using a managed property

Once that object has been injected it will then become part of the object graph, and will move with the root object through the data portal like the rest of the object graph.

mvklingeren commented 8 years ago

Thanks Rockford.

Can you tell me how to access the root of the object-graph, is my business-object added to that?

Or do you mean that i should extend my business object (via its baseclass, which inherits BusinessBase on its term) with a serializable property?

-edit: I understand that i can add / inject something to the baseclass of my business object; but ideally, i think it should be possible to give the Dataportal (client side) a configuration that could be used (server side).