csla icon indicating copy to clipboard operation
csla copied to clipboard

Implement multi-parameter and inject features for ObjectFactory

Open rockfordlhotka opened this issue 4 years ago • 3 comments

Enhance the factory data access models to support comparable features to the encapsulated models, including:

  • Passing multiple parameters to methods
  • Supporting DI injection (method level? constructor?)
  • Consider supporting the data portal operation attributes

rockfordlhotka avatar Jun 22 '20 19:06 rockfordlhotka

Hi Rocky,

With the requirement of using the DataPortal.Create method to create a command object instead of just newing one up in the command object class static method, the support for passing multiple parameters seems like the most useful change. Sending a single criteria object with all the properties to a create method just to initialize and return a command object to then just pass that command object back to the execute method seems overwhelmingly redundant. So I would think multiple parameters support for the create method would be the most important enhancement. With all that said, is there a reason that a command object needs to be created using the DataPortal.Create pattern? It seems to me that a command object is to carry user supplied criteria to an execution method with possible return values. So I can't see any scenario for a sophisticated creation routine.

When it comes to DI, from what I've read, CSLA can inject for missing additional parameters in method calls. It's something that can be done, but I'm unsure about the usefulness of this. I use a custom factory loader that resolves the object factories and injects through the constructor. I would lean towards this feature not being very useful for injecting into the methods since we control the entire object factory. However, I see constructor injection as useful with CSLA supporting it normally. As I said, I just created a fairly simple custom factory loader and used a service locater within it. It's an anti-pattern, but I'm OK with it as it's buried in a single place.

The operation attributes I would places at the lowest priority. The naming convention seems to work just fine for me. I use a base class that has the methods defined and override from there.

Thanks Rocky.

kellyethridge avatar Jun 23 '20 01:06 kellyethridge

I appreciate your input @kellyethridge.

I agree that the multiple parameters is very important.

I am torn on the DI, and am leaning toward doing both. As you note, we already have support so you can use your DI container to create the factory object, but CSLA can default to supporting constructor injection.

The thing is, the code that supports multiple parameter method invocation already also supports the Inject attribute. So the easiest thing to do is to reuse that existing code to enable multiple parameters. And that'll have the side-effect of also allowing method parameter injection.

Finally, I agree about the operation attributes. I personally think it would be confusing to support both the current ObjectFactory attribute scheme and also the new attributes.

rockfordlhotka avatar Jun 23 '20 14:06 rockfordlhotka

I think I'm going to push this change to CSLA 8, because it turns out to be quite challenging to implement, and there's time pressure to get CSLA 7 out soon - especially given that CSLA 8 should be targeted for later in 2023.

rockfordlhotka avatar Apr 19 '23 16:04 rockfordlhotka