|
|
|
Forum Newbie
      
Group: Forum Members
Last Login: 2009-02-16 17:50:38
Posts: 5,
Visits: 66
|
|
Hello everyone!
I am very new to ECO. Could someone please explain me about the class methods concept in ECO. For example, in ECO4 you can create a method in your model for some class, then in the Body you can specify some actions using EAL, generate the code and everything should work.
As an problematic example here is a part of the model (modeling the growth of a plant depending on a weather conditions):
PlantGrowth (Plant) 1 --- 0..* (Weather) Weather
In the Weather class I want to have a method GetWeather(). It should take PlantGrowth.Date and assign it's value to self.Date. Then I need to retrieve some data from external database using the same Date as a WHERE clause. Where should I set the connection and assign the retrieved values to the Weather object?
I have managed to do that in form's code using CurrencyManagerHandle, knowing both the current PlantGrowth object and Weather object and working with their attributes. But how can I implement that from the model side?
|
|
|
|
|
Supreme Being
      
Group: Administrators
Last Login: 2010-11-30 12:17:13
Posts: 1 230,
Visits: 1 382
|
|
To be able get this kind of informatoin when coding in the model, I suggest you register a service in your ecospace.
It would look something like this:
in the ecospace constructor:
RegisterEcoService(typeof(IMyService), new MyService(myConnectionString));
Where IMyService is the interface you want to be able to use in your domain classes, MyService is a class that implements this interface and myConnectoinString is just an arbitrary parameter to this class (for example the connectoin string to the external database).
In your domain claass you might write something like:
IMyService serv = AsIObject().ServiceProvider.GetEcoService(typeof(IMyService)) as IMyService;
Weather w = serv.GetWeatherByDate(aDate);
// do whatever
In ECO5, there are some new generic overloads that reduces the need for casting in the code above, but this code should work in both ECO4 and 5.
/Jonas Hogstrom [CapableObjects]
|
|
|
|