Ok, it really has it's limits.
The business object has dirty flags and is the only one knowing what has to be updated.
The ObjectFactory breaks the encapsulation and single responsibility quite a bit, but offers more flexibility. And it gives a better separation between the business layer and data access layer. Performance is very important but on the other hand it shouldn't get too complex!
It's more work for sure, but most of it works. And in the new 3.6.1 version Rocky implemented the LoadProperty method in the ObjectFactory.
But until now i bumped into several limitations:
1) Lazy loading
Using lazy loading with FieldManager.FieldExists(..) works fine until u want to let the root objectfactory persist the business object.
Problem: The objectfactory has no access to the Fieldmanager and so it'll trigger an LoadProperty.
2) DeletedList
A child as BLB contains deleted childs, an properted property in the BLB. Normally the DataPortal does a UpdateChild resulting in the Child_Update method being executed. Each item in the DeletedList is then being deleted, before the DeletedList is cleared.
Problem: The objectfactory has no access to the DeletedList, so it can't delete those items.
Can those 2 points be solved somehow?
Exposing the FieldManager to the ObjectFactory is not really nice..
The main reason i'm using the objectfactory is:
1) In the business and frontend assembly's there is totally no references needed to any assembly's required by the data access layer.
2) Our lists can have multiple objects comming from differend data sources, not only the customer database but also an webservice. The business object has a property so the objectfactory can update the correct database or webservice. VETRO? :)
How will it work when i the dataportal_xyz methods..
Anyway i hope u are wrong that we'll all discover that the endresult won't be great.
Maybe i can still dump the whole idea of using the objectfactory, it isn't too late yet... i'm still in a pre-fase for building an framework.
I might be wrong, but it appears to me that you can accomplish
1) and 2) without no need for Object Factory. Check Frank’s post on
StructureMap and Csla:
http://maonet.wordpress.com/2008/08/08/using-structuremap-to-mock-dataaccess-in-csla-bo/
One important thing to note is that in Frank’s code
example “ObjectFactory” is a StructureMap class. It happens
to have a same name as Csla ObjectFactory, but serves a different purpose.
I truly believe that using StructureMap(Unity or Windsor, or
some other IoC tool) to separate out dependencies is a better/simpler way to do
this, and for now lets leave ObjectFactory as a placeholder for future EF
integration.
Nermin
From: rfcdejong
[mailto:cslanet@lhotka.net]
Sent: Wednesday, February 04, 2009 10:04 AM
To: Nermin Dibek
Subject: Re: [CSLA .NET] ObjectFactory
The main reason i'm using the objectfactory is:
1) In the business and frontend assembly's there is totally no references
needed to any assembly's required by the data access layer.
2) Our lists can have multiple objects comming from differend data sources,
not only the customer database but also an webservice. The business object
has a property so the objectfactory can update the correct database or
webservice. VETRO? :)
How will it work when i the dataportal_xyz methods..
Anyway i hope u are wrong that we'll all discover that the endresult won't
be great.
Maybe i can still dump the whole idea of using the objectfactory, it isn't too
late yet... i'm still in a pre-fase for building an framework.
Nermin is correct, it is absolutely possible to build a nice DAL
for use directly from the DataPortal_XYZ methods. I prototyped this a long time
ago in the DeepData sample app, and Frank applied some really nice patterns to
the overall concept.
One key thing to note about both DeepData and Frank’s
post, is the use of a DTO to transport data between the business object and
DAL. This is the primary mechanism available for decoupling the two objects,
and it can help preserve encapsulation.
The use of DTOs incurs overhead and requires more code, but the
end result is good from an architectural perspective.
Rocky
I’m not trying to discourage you from using the object
factory concept – don’t get me wrong.
I’m just saying that it is a new concept, and so my implementation
thus far has been as conservative as possible, because I don’t know yet
what is a good or bad practice.
I totally understand the desire to have an external DAL
assembly!
And most of the problems I listed in my previous post are
universal to having an external DAL. That concept, in general, forces you to
break encapsulation. And I have yet to see a solution that didn’t incur a
lot of tight coupling.
Rocky
From: rfcdejong
[mailto:cslanet@lhotka.net]
Sent: Wednesday, February 04, 2009 10:03 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] ObjectFactory
The main reason i'm using the objectfactory is:
1) In the business and frontend assembly's there is totally no references
needed to any assembly's required by the data access layer.
2) Our lists can have multiple objects comming from differend data sources,
not only the customer database but also an webservice. The business object
has a property so the objectfactory can update the correct database or
webservice. VETRO? :)
How will it work when i the dataportal_xyz methods..
Anyway i hope u are wrong that we'll all discover that the endresult won't
be great.
Maybe i can still dump the whole idea of using the objectfactory, it isn't too
late yet... i'm still in a pre-fase for building an framework.
As I’ve said in a couple other threads, the field manager
exists to avoid the requirement for reflection during serialization. Field
manager doesn’t exist for data access or data factories or any of these concepts.
It exists so it is possible to serialize an object graph without reflection
(for Silverlight).
Rocky
From: FrankM
[mailto:cslanet@lhotka.net]
Sent: Wednesday, February 04, 2009 10:02 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] ObjectFactory
1) Exposing FieldManager to be public.
2) I don't think using ObjectFactory for BusinessList is a good idea, it only
makes things more complicated. Just leave those Child_XYZ methods still in
ChildBO.
To solve the problem completely, move relationship to ORM, then you can retire
FieldManger from BO.
Copyright (c) Marimer LLC