New Posts New Posts RSS Feed: defining default composition context
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Forum Lockeddefining default composition context

 Post Reply Post Reply
Author
midnit View Drop Down
Senior Member
Senior Member
Avatar

Joined: 22-Jun-2009
Location: Charlotte
Posts: 112
Post Options Post Options   Quote midnit Quote  Post ReplyReply Direct Link To This Post Topic: defining default composition context
    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 :)
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
midnit View Drop Down
Senior Member
Senior Member
Avatar

Joined: 22-Jun-2009
Location: Charlotte
Posts: 112
Post Options Post Options   Quote midnit Quote  Post ReplyReply Direct Link To This Post 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?
 
 
 
Back to Top
midnit View Drop Down
Senior Member
Senior Member
Avatar

Joined: 22-Jun-2009
Location: Charlotte
Posts: 112
Post Options Post Options   Quote midnit Quote  Post ReplyReply Direct Link To This Post 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?


Edited by midnit - 20-Mar-2012 at 8:32am
Back to Top
midnit View Drop Down
Senior Member
Senior Member
Avatar

Joined: 22-Jun-2009
Location: Charlotte
Posts: 112
Post Options Post Options   Quote midnit Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 20-Mar-2012 at 11:24am
Hmm, have you marked your X and Y SaveInterceptors with System.ComponentModel.Composition.PartNotDiscoverable attribute?
Back to Top
midnit View Drop Down
Senior Member
Senior Member
Avatar

Joined: 22-Jun-2009
Location: Charlotte
Posts: 112
Post Options Post Options   Quote midnit Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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 (Built against our current version of 6.1.6.0)

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


Edited by DenisK - 20-Mar-2012 at 1:08pm
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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

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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down