CSLA .NET and Microsoft Unity (IoC, DI)

CSLA .NET and Microsoft Unity (IoC, DI)

Old forum URL: forums.lhotka.net/forums/t/11819.aspx


BeyondNet posted on Tuesday, February 05, 2013

Good Afternoom

I need to test with respect to possibility to use ASP .NET MVC 4 + CSLA .NET 4.3 + Repository Pattern. In my tests found the following problem with "Microsoft Unity".  I have a message  error when I use use the Data Portal with WCF (3 Tiers):

System.Runtime.Serialization.InvalidDataContractException: Type 'System.Collections.Generic.IEnumerable`1[Microsoft.Practices.Unity.ContainerRegistration]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.  If the type is a collection, consider marking it with the CollectionDataContractAttribute.  See the Microsoft .NET Framework documentation for other supported types.

Please, do you mind if you give me some suggestions. 

 

P.D. I'm using the attribute Serializable()

Best Regards

 

 

JonnyBee replied on Wednesday, February 06, 2013

An Interface is NOT serializable. So for a comparison with f.ex MEF you must mark the injected Repository and eventual IoC container as NonSerialized and NotUndoable.

    [NonSerialized, NotUndoable]
    private IRootDataAccess _myRootDataAccess;

    [EditorBrowsable(EditorBrowsableState.Never)]
    [Import(typeof(IRootDataAccess))]
    private IRootDataAccess MyRootDataAccess
    {
      get { return _myRootDataAccess; }
      set { _myRootDataAccess = value; }
    }

BeyondNet replied on Wednesday, February 06, 2013

JonnyBee thanks for response.

Can you help me with some sample? 

JonnyBee replied on Wednesday, February 06, 2013

Download the source from http://cslacontrib.codeplex.com 

There is a separate CslaContrib.Mef project that contains base classes and MEF IoC container
and in the Samples download you will find both Repository and ObjectFactory sample.

BeyondNet replied on Wednesday, February 06, 2013

Jonny

 

Thanks for your advise

Copyright (c) Marimer LLC