New Posts New Posts RSS Feed: Can't override the Default CompositionContext
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Can't override the Default CompositionContext

 Post Reply Post Reply
Author
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 Topic: Can't override the Default CompositionContext
    Posted: 04-Apr-2012 at 4:40pm
Hi Walid,

This seems to be a bug in DevForce Silverlight. I was trying my test in a console app and it works. Do the same test in SL and it fails just like you indicated. The Default override was ignored. I'll be filing a bug report.

NOTE: This post is moved as it proves to be a non-cocktail related issue.


Edited by DenisK - 04-Apr-2012 at 6:59pm
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 04-Apr-2012 at 2:00am
Hi Denis,

I did it and it's not working either

Here is the class where I defined the Default CompositionContext. The main application has a reference on the silverlight Domain hosting this Resolver.
Note that I have others Resolver, located in others Domain assembly (they might or might not be downloaded by request). Each of them declare their own CompositionContext, only here the Default is overriden. 

    public class MyCompositionContextResolver : ICompositionContextResolver 
    {
        public static CompositionContext MyDefault = CompositionContext.Default
#if !SILVERLIGHT
                    .WithGenerator(typeof(CommonEntityServerSaveInterceptor))
#endif
                    .WithName(CompositionContext.Default.Name);
 
        public CompositionContext GetCompositionContext(string compositionContextName)
        {
            return null;
        }
    }

Here is the definition of my Interceptor 

    public class CommonEntityServerSaveInterceptorEntityServerSaveInterceptor
    {
        protected override bool ExecuteSave()
        {
            throw new Exception("CommonEntityServerSaveInterceptor");
        }
    }

Still, I can save entities to my database, no exception as I would have expected.
Below the log showing devforce doesn't care about the override. 


2012-04-04 10:49:57  IdeaBlade.Core.Composition.CompositionHost:CheckMultiExport CompositionContext: '-IbDefault-' - Probed for any 'IIdGenerator' and found 'IdeaBlade.EntityModel.StoreGeneratedIdGenerator'. 
2012-04-04 10:49:57  IdeaBlade.Core.Composition.CompositionHost:CheckMultiExport CompositionContext: '-IbDefault-' - Probed for non-default 'IConcurrencyStrategy' and found no matching exports. 
2012-04-04 10:49:57  IdeaBlade.Core.Composition.CompositionHost:CheckSingleExport CompositionContext: '-IbDefault-' - Probed for default 'IConcurrencyStrategy' and found 'IdeaBlade.EntityModel.DefaultConcurrencyValueSetter'. 
2012-04-04 10:49:57  IdeaBlade.Core.Composition.CompositionHost:CheckMultiExport CompositionContext: '-IbDefault-' - Probed for non-default 'IVerifierProvider' and found no matching exports. 
2012-04-04 10:49:57  IdeaBlade.Core.Composition.CompositionHost:CheckSingleExport CompositionContext: '-IbDefault-' - Probed for any 'EntityServerSaveInterceptor' and found 'IdeaBlade.EntityModel.Server.EntityServerSaveInterceptor'. 



Could the ConnectionOption defined in Cocktail (which seems to gice the compositioncontext to the manager) be the cause of this behavior ? 



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 12:55am
Hi Walid,

It looks like GetCompositionContext will not get called when using CompositionContext.Default. I'll be checking with a lead architect to find out whether this behavior is a bug or intended.

For the time being, to override the default CompositionContext, you can declare a public static variable in your CompositionContextResolver class as follows:

public class CompositionContextResolver : ICompositionContextResolver {
    public static CompositionContext MyDefault = CompositionContext.Default
      .WithGenerator(typeof(MyDefaultEntityServerQueryInterceptor))
      .WithGenerator(typeof(MyDefaultEntityServerSaveInterceptor))
      .WithName(CompositionContext.Default.Name);

    public CompositionContext GetCompositionContext(string compositionContextName) {
          //return other custom CompositionContext
    }
}
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 03-Apr-2012 at 9:54am
Hi,

I am posting my issue in this forum as I am guessing it is somehow related to coktail


I need to have many EntitySaveServerInterceptor in my project. Based on this post (http://www.ideablade.com/forum/forum_posts.asp?TID=3344&KW=WithFilter&title=defining-default-composition-context) I created many CompositionContext and overrided the IbDefault one.

The specifics CompositionContext seems to work, but not the Default one. I tried using both method (with PartNotDiscoverable and with MetadataExport) but without success.
Using the MetadataExport result in an exception saying there is many EntitySaveServerInterceptor definition (they are all with a different MetadataExport).

The exemple from the post below works fine. In my project the Default override doesn't. the only difference for me is Cocktail.
I then tried to modify TempHire in order to  have an EntityServerSaveInterceptor with the IbDefault context.


I have the same issue, it never use it. 
To reproduce it, just replace the content of the CompositionContextResolver file with the text below.

Am I forgetting something or it is  a bug in cocktail/devforce ?


using System;
using IdeaBlade.Core.Composition;
#if !SILVERLIGHT
using System.ComponentModel.Composition;
using IdeaBlade.EntityModel.Server;
#endif
 
namespace Security.Composition
{
#if !SILVERLIGHT
    [PartNotDiscoverable]
    public class MyServerSaveInterceptorEntityServerSaveInterceptor
    {
        protected override bool ExecuteSave()
        {
            throw new Exception("MySaveInterceptor");
        }
    }
#endif
 
    public class CompositionContextResolver : ICompositionContextResolver
    {
        private const string TempHireContextName = "TempHireFake";
 
        public static CompositionContext TempHireFake = CompositionContext.Fake
#if !SILVERLIGHT
            .WithGenerator(typeof(FakeLoginManager))
#endif
            .WithName(TempHireContextName);
 
        #region ICompositionContextResolver Members
 
        public CompositionContext GetCompositionContext(string compositionContextName)
        {
            switch (compositionContextName)
            {
                case TempHireContextName:
                    return TempHireFake;
                default:
                    // the default override
                    return CompositionContext.Default
#if !SILVERLIGHT
                        .WithGenerator(typeof(MyServerSaveInterceptor))
#endif
                        .WithName(CompositionContext.Default.Name);
            }
        }
        #endregion
    }
}






Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down