Configuring a very simple test

Configuring a very simple test

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


Mark Sulkowski posted on Friday, October 21, 2011

I'm using Visual Studio 2008.

I'd like to create a very simple test of the DataPortal.  Preferably, this will be done using a plain Console Application, but if I have to use a Windows Form, that will be fine.

In one assembly, I have a BusinessObject class defined as a child of BusinessBase<T>.  It is marked as Serializable, and  as using an ObjectFactory.  It has just one field and related property:

private static readonly PropertyInfo<System.Guid> _GUIDProperty = RegisterProperty<System.Guid>(p => p.GUID, String.Empty);

public System.Guid GUID { get { return GetProperty(_GUIDProperty); } private set { SetProperty(_GUIDProperty, value); } }

 

And one synchronous factory method:

public static BusinessObject GetNewInstance()

{

return DataPortal.Create<BusinessObject>(); }

 

 

In a different assembly, there is a class that inherits from ObjectFactory that the business object will try to use.  To keep things simple, I will simply return an Activator created instance of the Business Object class.

When I run my test, I get a DataPortalException with the message DataPortal-Create failed ().  I assume this is the expected result for when the application hasn't been configured yet.  Configuration is what I would like to do.

What are the basics involved in configuring the Console Application (or Windows Form, if need be) to let the BusinessObject know how to communicate with its counterpart ObjectFactory object?  Is this as simple a matter as a few app.config entries?

I don't care much about authentication issues at this point. I just want to see the Dataportal.Create method work.

 

Mark Sulkowski

DigRAD Solutions AB

JonnyBee replied on Friday, October 21, 2011

The basic part is - add the ObjectFactory attribute (with fully qualified name for the object factory class)  to your BO class and implement the Create method in that ObjectFactory class. 

Look at the sample SimpleNTier for how to use these.

  [Serializable]
  [Csla.Server.ObjectFactory("DataAccess.OrderFactory, DataAccess")]
  public class Order : BusinessBase<Order>

    public static Order NewOrder()
    {
      return DataPortal.Create<Order>();
    }

and

  public class OrderFactory : ObjectFactory
  {
    public Order Create()
    {
      var obj = (Order)MethodCaller.CreateInstance(typeof(Order));
      LoadProperty(obj, Order.IdProperty, -1);
      MarkNew(obj);
      CheckRules(obj);
      return obj;
    }

 

 

 

Mark Sulkowski replied on Monday, November 07, 2011

Thanks for the help, JonnyBee, but I was already doing something very similar to what you had suggested.  The only substantial difference was that I was using Activator instead of MethodCaller in the Create method.

I tried using MethodCaller, but I still get the same DataPortalException.  I have been using the Serializable and ObjectFactory attributes on the business object, and I'm reasonably certain that I am giving the correct string.  (The string is "DALTest.BusinessObjectFactory, DALTest" and DALTest is the name of the assembly.)

The only thing I can think of is that the business layer doesn't know where to go to reach the DAL.  Could there be some app.config style settings that I need to set?

I'll give more of my code if that helps.  I get a DataPortalException when DataPortal.Create is called.  I get this exception even if I comment out my Create method code and simply return a null. 

[

Serializable]

 

[Csla.Server.ObjectFactory(FactoryNames.BusinessObjectFactoryName)]

public partial class BusinessObject : DigRADBusinessBase<BusinessObject>

 

 

 

#region

 

 

 

private static readonly PropertyInfo<System.Guid> _GUIDProperty = RegisterProperty<System.Guid>(p => p.GUID, String.Empty);

 

 

 

 

public System.Guid GUID

{

properties

 

 

 

 

get { return GetProperty(_GUIDProperty); }

private set { SetProperty(_GUIDProperty, value);

}

 

#endregionSynchronous Factory Methods

#region

 

 

public static BusinessObject GetNewInstance() return DataPortal.Create<BusinessObject>(); }

{

#endregion

}

 

 

 

 

public partial class BusinessObjectFactory : ObjectFactory

{

#region 

 

 

Create

 

public BusinessObject Create()

{

 

var obj = MethodCaller.CreateInstance(typeof(BusinessObject)) as BusinessObject;

MarkNew(obj);

CheckRules(obj);

 

return obj;

}

}

 

StefanCop replied on Monday, November 07, 2011

You DALTest.dll has to be in the same directory as your console .exe (I assume you run without config/LocalProxy/2-tier; otherwise the dll should be located in the server's directory).

Your factory has to implement public BusinessObject Create() , as you've posted.  And I assume the factory is in a DalTest namespace.

Copyright (c) Marimer LLC