Print Page | Close Window

Model Extension via MEF

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3368
Printed Date: 28-Mar-2025 at 10:37am


Topic: Model Extension via MEF
Posted By: Vonzkie
Subject: Model Extension via MEF
Date Posted: 02-Apr-2012 at 1:36am
Hi,

Assuming I have a project named Domain where my Model resides that has 1 Entity with a definition as follows:

MyEntity
- ID (int)
- MyDescription (string)
- MyOtherField (datetime)

I have a Business Rule Project that is accessing my Domain project.

What I'm trying to do is to have a "customized" Domain project that has the same Model and Entity but with additional fields such as:

MyEntity
- ID (int)
- MyDescription (string)
- MyOtherField (datetime)
- MyCustomOtherField (string)

Now what I want to accomplished is that, I don't want to rewrite my whole Business Rule project to use the customized Domain project but instead use MEF or any other technique to just simply plug and play this customization.

What is the best way to do it in Devforce?

Thanks,
Von




Replies:
Posted By: Vonzkie
Date Posted: 02-Apr-2012 at 1:38am
Note: By not using Code First approach here..


Posted By: DenisK
Date Posted: 02-Apr-2012 at 3:50pm
Hi Vonzkie,

If I understand correctly, it seems that you want to add a custom property to your existing Entity classes. Each Entity class generated by DevForce is a partial class. So you can extend it however you want by simply declaring another partial class of the same Entity.

See  http://drc.ideablade.com/xwiki/bin/view/Documentation/model-partial-class-file - http://drc.ideablade.com/xwiki/bin/view/Documentation/model-partial-class-file  for more details.


Posted By: Vonzkie
Date Posted: 02-Apr-2012 at 5:59pm
Hi,

No, I'm not pertaining to partial class.. I'm talking about different assembly here w/c holds another model and entities (with the same type that I used with the Domain Project) to which we will modify and let the Business Layer project to use the customized one..

Thanks,
Von


Posted By: DenisK
Date Posted: 03-Apr-2012 at 3:03pm
Sorry Von but I'm still lost as to what you're trying to achieve.

You have a model with Assembly A containing EntityTypeA

AssemblyA
  Namespace DomainModelA
    public partial class EntityTypeA

Then you want another Assembly B with the exact model composition but with additional fields

AssemblyB
  Namespace DomainModelB
   public partial class EntityTypeA
    public int ExtraProp { get; set; }

Unfortunately, this is not possible in .NET if this is what you're trying to achieve. 


Posted By: Vonzkie
Date Posted: 03-Apr-2012 at 3:57pm
Hi Denis,

I agree that this is something weird but I'm just asking the possibility of this one.
I'll try to rephrase it, the concept is like this:

We as a software provider has this set of base components of our product.

Example:

1. OurCompany.DomainModel
2. OurCompany.BusinessLayer
3. OurCompany.Forms

Where Forms makes use of BusinessLayer w/c makes use of the DomainModel for the dataaccess. (So there will be entities on that model)
Now, we have a feature of our software called ICE (Intergrated Code Expansion) so kinda plugin or so.
We are letting our customer to override some of the Forms, BusinessLayer and database schema (this is the time  that ORM is not yet existing) by inheriting them and calling the customized components instead of the base one (but in the perspective of the base application, it is just calling the default component)

The requirement of our project now is to make it ICEable, Forms and BusinessLayer has no problem and we see MEF as a way to go to do the work but our problem would be the Model. We're not giving the customer the source code of all the base components, they are just inheriting it, overriding or adding some methods, add some bindings, add some controls to the inherited form and we will call the customized one instead of the default. The problem is the Model, how can we extend the model by just inheriting it our any other Devforce approach and let BusinessLayer use the extended one rather than the default.

Thanks,
Von


Posted By: DenisK
Date Posted: 04-Apr-2012 at 12:29pm
Hmm, it sounds like your question is bordering on architecture and unfortunately I'm not qualified to give such advice. You might want to contact your account representative to see if you can have a discussion with a senior consultant.



Print Page | Close Window