Print Page | Close Window

defining default composition context

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=3344
Printed Date: 21-Nov-2019 at 5:07am


Topic: defining default composition context
Posted By: midnit
Subject: defining default composition context
Date Posted: 19-Mar-2012 at 8:00am

I am missing a bit regarding how CompositionContext is working and what I need to do to get my desired results.

Previously we had just 1 save interceptor and life was well. Then we added another save interceptor and life became not so well. So then I read your CompositionContext documentation and life became...a little muddy, but well enough after a little trial and error. I added some metadata to the saveinterceptors and this works well for the entitymanagers where we define the context, but I would like to not have to declare the context on every entitymanager and I get the feeling from the documentation that this IS possible but I am confused as to how.
 
I created a custom CompositionContextResolver and started seeing what happens in GetCompositionContext and I see that without a context defined in the entitymanager constructor...it never gets hit so I can't change its behavior here. So, where can I achieve this? I would like to define what the "-IbDefault-" context means or something to avoid having to declare the context on every entitymanager I create.
 
Please enlighten me :)



Replies:
Posted By: DenisK
Date Posted: 19-Mar-2012 at 5:17pm
Hi midnit;

You can "override" -IbDefault- context implementation by defining a default CompositionContext in your CompositionContextResolver. The key is with the .WithName extension method.

public class MyCompositionContextResolver : BaseCompositionContextResolver {

  public static CompositionContext MyDefault = CompositionContext.Default
    .WithGenerator(typeof(AdminEntityServerSaveInterceptor))
    .WithGenerator(typeof(AdminEntityServerQueryInterceptor))
    .WithName(CompositionContext.Default.Name);

}

//Any query or save made by an EntityManager created without declaring the context will use the above //AdminEntityServerSaveInterceptor and AdminEntityServerQueryInterceptor


Let me know if this is not what you're looking for.


Posted By: midnit
Date Posted: 20-Mar-2012 at 5:26am
I have seen that in the documentation and I admit I did not try it but that was because it did not fit (in my head) what I thought I wanted to do. This "appears" to me that I would have to use MyCompositionContextResolver.MyDefault in every EntityManager constructor to get this composition:
 

var em = new EntityManager(true, null, DefaultSomething, MyCompositionContextResolver.MyDefault)
 
But, since you are repeating it I assume I need to fit it in my head :) Is this going to redefine what CompositionContext.Default means without using actually using MyDefault? I need just the declaration?
 
 
 


Posted By: midnit
Date Posted: 20-Mar-2012 at 8:31am
Bah, I didn't read the last comment in your code section...that answers my reply.
 
So this defines the specific implementations to use for those two types, and the rest of the types are loaded as normal? So if I added two more of a different type (say, login manager) I would get the composition error until I went and added one to this default line?
 
How would I define it such that it would not load any custom types without explicitly declaring the context when creating an EM?


Posted By: midnit
Date Posted: 20-Mar-2012 at 10:27am
I believe I am asking the wrong questions.
 
I currently want all my EM's to not load anything special. I want 2 particular EM's to load a custom saveinterceptor each. So every instance of XEntityManager should load XSaveInterceptor, likewise every YEntityManager should load YSaveInterceptor - everything else should ignore those save interceptors. Those are my thoughts today...
 
I have X and Y Em's loading their interceptors...but all the other Em's try to load them both unless I explicitly give a Context on creation which is needless busy work.
 
My interceptors are defined like:

    [InheritedExport(typeof(EntityServerSaveInterceptor))]
    [ExportMetadata("GCS","X")]
    class SaveXInterceptor : EntityServerSaveInterceptor
 
My context resolver overrides GetCompositionContext:

        public override CompositionContext GetCompositionContext(string compositionContextName)
        {
            var filter = CompositionContext.BuildExportFilter("GCS", compositionContextName);
            return CompositionContext.Default.WithFilter(filter).WithName(compositionContextName);
        }
 
Obviously I am on the wrong path...guide me.
 
Thank you.


Posted By: DenisK
Date Posted: 20-Mar-2012 at 11:24am
Hmm, have you marked your X and Y SaveInterceptors with System.ComponentModel.Composition.PartNotDiscoverable attribute?


Posted By: midnit
Date Posted: 20-Mar-2012 at 11:43am
I tested that and they were ignored by everything I believe. I did not try building a special CompositionContext for those Em's though, just tried passing the contextName.


Posted By: DenisK
Date Posted: 20-Mar-2012 at 1:03pm
I see. Well, I think this is one of those concept that's easier to show in a sample solution than to explain.

I've created a simple one showing how I create my custom composition context resolver with the 2 discovery methods shown in the DRC.

Discovery with types - MyCustomCCResolverWithTypes.cs
Discover with metadata filters - MyCustomCCResolverWithMetadataFilters.cs

The one with the types is commented out so it doesn't conflict. And also due to the fact that you're already gone down the metadata method of discovery path.

uploads/912/Console_T11680.zip - uploads/912/Console_T11680.zip  (Built against our current version of 6.1.6.0)

Let me know if this is or is not what you're looking for.


Posted By: DenisK
Date Posted: 04-Apr-2012 at 4:42pm
Another customer had asked the same question here.  http://www.ideablade.com/forum/forum_posts.asp?TID=3372&PID=13232#13232 - http://www.ideablade.com/forum/forum_posts.asp?TID=3372&PID=13232#13232

After further investigation, it turns out that this is a bug in our DevForce Silverlight. (I was testing with a console app previously). I'll be filing a bug report.



Print Page | Close Window