CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Using the business objects to invoke a mock DAL ... couple questions ...

Answered (Verified) This post has 1 verified answer | 19 Replies | 2 Followers

Top 200 Contributor
46 Posts
mattruma posted on Thu, Feb 3 2011 9:12 AM

We really want to be able to test our business objects without hitting a database ... so I spent some time with the CSLA book and watched the 3.8 Core videos and so this concept of using the business object to invoke the DAL. I saw in the demo where Rocky is loading from an ADO DAL and a MOCK DAL. This looks like just what we need!

A couple of changes we are going to make is actually have something like ICustomerFactory and ICustomer, so we can pass a Customer business object that implements ICustomer to the ICustomerFactory ... this way we don't need to pass in a ton of parameters.  I'm curious if this makes sense and if other have a better way.

The other thing, is that with the Mock DAL we would like to "fill" it with different data at different times ... mainly for different test scenarios. I noticed in Rocky's Mock DAL he is prepopulating it with data. I would like to do this dynamically ... or even something like an in memory database? Again, I just need the data to be tweaked for each different test scenario. Is anyone else trying to do this ... and if so, I'd appreciate any help you could provide!

Thanks! Smile

Answered (Verified) Verified Answer

Top 10 Contributor
1,772 Posts
Verified by mattruma

My misunderstanding, I thought you were thinking of the ObjectFactory implementation in Csla.

The cslacontrib also has a sample shows a Repository pattern following your line of thinking. Have a look at the MEF Repository sample.

Have a look at my blog post too: http://jonnybekkum.wordpress.com/2010/12/30/cslacontrib-mef-and-repository-pattern-with-csla4/

Jonny Bekkum, Norway CslaContrib Coordinator

All Replies

Top 10 Contributor
1,772 Posts

You could change access to the injected property to private. MEF can inject into public, internal and private properties.

If you wish to keep the property public and hidden in designers/intellisense that use your assembly you could add the EditorBrowsableAttribute to the property:

    [EditorBrowsable(EditorBrowsableState.Never)]

For more info on this attribute:
http://msdn.microsoft.com/en-us/library/system.componentmodel.editorbrowsableattribute.aspx

Jonny Bekkum, Norway CslaContrib Coordinator

Top 200 Contributor
46 Posts

I am working through this now in my test class and am now receiving the following error:

Type 'CslaContrib.MEF.MefBusinessBase`1[[CompanyName.ProjectName.Business.Customer, CompanyName.ProjectName.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' in Assembly 'CslaContrib.MEF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

Is it as simple to mark the MefBusinessBase as Serializable or this masking some other problem?

Top 200 Contributor
46 Posts

Added the [Serializable] Attribute to the MEF objects and everything seems to work ... tests pass ... confirming right now.

Top 10 Contributor
1,772 Posts

Thanks Matt.

Cant believe i missed the [Serializable] attribute.

I have added [Serializable] to all base classes in CslaContrib and correct ones are available for download now.

 

Jonny Bekkum, Norway CslaContrib Coordinator

Top 200 Contributor
46 Posts

Thanks again Jonny!

Page 2 of 2 (20 items) < Previous 1 2 | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems