Mef Contrib Silverlight version?

Nov 3, 2009 at 9:51 AM

Hi,

Are there any plans for a mef contrib Silverlight version/build?

Cheers

Adam

 

Coordinator
Nov 3, 2009 at 9:54 AM
Non that I know of (I'm not a silverlight dev myself), but if you think you could contribute the nessecary code
inforder for it to work then please let me know and we'll see if we can sort something out :)

On Tue, Nov 3, 2009 at 10:52 AM, raymartinshair <notifications@codeplex.com> wrote:

From: raymartinshair

Hi,

Are there any plans for a mef contrib Silverlight version/build?

Cheers

Adam

 

Read the full discussion online.

To add a post to this discussion, reply to this email (MEFContrib@discussions.codeplex.com)

To start a new discussion for this project, email MEFContrib@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Nov 3, 2009 at 11:17 AM
TheCodeJunkie wrote:
Non that I know of (I'm not a silverlight dev myself), but if you think you could contribute the nessecary code
inforder for it to work then please let me know and we'll see if we can sort something out :)

On Tue, Nov 3, 2009 at 10:52 AM, raymartinshair <notifications@codeplex.com> wrote:

From: raymartinshair

Hi,

Are there any plans for a mef contrib Silverlight version/build?

Cheers

Adam

Hi,

Ok I bit the bullet and downloaded the MefContrib 0.7.0.0 Source Code and performed the following tasks.

  • Added a silverlight project for MefContrib.Extensions.Generics, MefContrib.Integration.Unity and the MefContrib.Models.Provider VS projects.
  • I then installed the Composite Application Guidance for WPF and Silverlight Project Linker: Synchronization Tool
  • Once that was installed I linked the projects and excluded and reincluded each of the source projects (original projects) code files and folders.
  • I manually added a link to the shared assembly info file to each of the silverlight project.
  • I added a unity SL 1.2 SL folder to the dependencies folder and put the SL build of unity in the folder. 
  • I added a mef preview 7 SL folder to the dependencies folder and put the SL build of mef in the folder.
  • I then added references to the above Sl builds of dependencies to the appropriate mef contrib SL projects.
  • I then built the solution.

The SL projects MefContrib.Extensions.Generics, MefContrib.Integration.Unity built ok but the SL version of the MefContrib.Models.Provider project had a few issues.

The first issue was that SL doesn't support much in the way of anything in the System.Configuration assembly. So I removed the links code files in the Definitions-Configurable folder (11 files in total).

The 2nd issue was a syntax issue located in the DefinitionProviderPartCatalog class in the GetDefinition method. The String.Compare method signature is not supported by SL.

Orginal Code:

 

public ProviderComposablePartDefinition GetDefinition(object instance)
        {
            var matches =
                from definition in this.GetComposablePartDefinitions()
                where (string.Compare(definition.Type.FullName, instance.GetType().FullName, bool) == 0)
                select definition;

            return matches.FirstOrDefault();
        }

 

 

 

Modified Code:

public ProviderComposablePartDefinition GetDefinition(object instance)
        {
            var matches =
                from definition in this.GetComposablePartDefinitions()
                where (string.Compare(definition.Type.FullName, instance.GetType().FullName, System.StringComparison.CurrentCultureIgnoreCase) == 0)
                select definition;

            return matches.FirstOrDefault();
        }

And what do you know the code compiled.

 

I haven't had a chance to look at the unit test projects yet.

What the best way for me to get the code back to you ????

Cheers

Adam

 

 

Nov 10, 2009 at 2:46 PM

Hello

I'ld like to use the mefContrib in an Silverlight application could you send us the dll build for silverlight ?

 

Thanks

Nov 10, 2009 at 9:37 PM
Edited Nov 11, 2009 at 12:50 AM

ok, It seems I was a tad optimistic in my last post.

 

I decided to re-implement the existing unit tests in silverlight see below for results.

  • MefContrib.Extensions.Generics.Silverlight.Tests   (10 out of 10 tests passed.)
  • MefContrib.Integration.Unity.Silverlight.Tests        (16 out of 23 tests failed) ;-(
  • MefContrib.Models.Provider.Silverlight.Tests        (121 out 121 tests passed)

The unit tests that are failing in the MefContrib.Integration.Unity.Silverlight.Tests project are all nearly failing at the same point. See highlighted line below. Mef contrib peoples any ideas????

 

 

        /// <summary>
        /// Represents a MEF lifetime strategy which tries to resolve desired
        /// component via MEF. If succeeded, build process is completed.
        /// </summary>
        private class CompositionLifetimeStrategy : BuilderStrategy
{
public override void PreBuildUp(IBuilderContext context)
{
var container = context.Locator.Get<CompositionContainer>();
var buildKey = (NamedTypeBuildKey)context.BuildKey;

try { var exports = container.GetExports(buildKey.Type, null, buildKey.Name);

if (exports.Count() == 0)
return;

if (exports.Count() > 1)
throw new CompositionException(Resources.TooManyInstances);

if (exports.First().Metadata is IDictionary<string, object>)
{
var metadata = (IDictionary<string, object>)exports.First().Metadata;
if (metadata.ContainsKey(ExporterConstants.IsExternallyProvidedMetadataName) &&
true.Equals(metadata[ExporterConstants.IsExternallyProvidedMetadataName]))
return;
}

context.Existing = exports.First().Value;
context.BuildComplete = true;
}
catch (Exception)
{
context.BuildComplete = false;
throw;
}
}
}

 

 

Here's a list of the failed test results.

 

Microsoft.Practices.Unity.ResolutionFailedException
Resolution of the dependency failed, type = "MefContrib.Integration.Unity.Tests.Helpers.IMefComponent", name = "component2". Exception message is: The current build operation (build key Build Key[MefContrib.Integration.Unity.Tests.Helpers.IMefComponent, component2]) failed: System.ComponentModel.Composition.ExportServices.CreateSemiStronglyTypedLazy(System.ComponentModel.Composition.Primitives.Export) (Strategy type CompositionLifetimeStrategy, index 2)
Microsoft.Practices.Unity.ResolutionFailedException
Resolution of the dependency failed, type = "MefContrib.Integration.Unity.Tests.Helpers.IUnityComponent", name = "". Exception message is: The current build operation (build key Build Key[MefContrib.Integration.Unity.Tests.Helpers.UnityComponent2, null]) failed: System.ComponentModel.Composition.ExportServices.CreateSemiStronglyTypedLazy(System.ComponentModel.Composition.Primitives.Export) (Strategy type CompositionLifetimeStrategy, index 2)
Microsoft.Practices.Unity.ResolutionFailedException
Resolution of the dependency failed, type = "MefContrib.Integration.Unity.Tests.Helpers.IMefComponent", name = "". Exception message is: The current build operation (build key Build Key[MefContrib.Integration.Unity.Tests.Helpers.IMefComponent, null]) failed: System.ComponentModel.Composition.ExportServices.CreateSemiStronglyTypedLazy(System.ComponentModel.Composition.Primitives.Export) (Strategy type CompositionLifetimeStrategy, index 2)
Microsoft.Practices.Unity.ResolutionFailedException
Resolution of the dependency failed, type = "MefContrib.Integration.Unity.Tests.Helpers.IUnityComponent", name = "". Exception message is: The current build operation (build key Build Key[MefContrib.Integration.Unity.Tests.Helpers.UnityComponent1, null]) failed: System.ComponentModel.Composition.ExportServices.CreateSemiStronglyTypedLazy(System.ComponentModel.Composition.Primitives.Export) (Strategy type CompositionLifetimeStrategy, index 2)
Microsoft.Practices.Unity.ResolutionFailedException
Resolution of the dependency failed, type = "MefContrib.Integration.Unity.Tests.Helpers.IUnityComponent", name = "". Exception message is: The current build operation (build key Build Key[MefContrib.Integration.Unity.Tests.Helpers.UnityComponent3, null]) failed: System.ComponentModel.Composition.ExportServices.CreateSemiStronglyTypedLazy(System.ComponentModel.Composition.Primitives.Export) (Strategy type CompositionLifetimeStrategy, index 2)
Microsoft.Practices.Unity.ResolutionFailedException
Resolution of the dependency failed, type = "MefContrib.Integration.Unity.Tests.Helpers.IUnityComponent", name = "". Exception message is: The current build operation (build key Build Key[MefContrib.Integration.Unity.Tests.Helpers.UnityComponent2, null]) failed: System.ComponentModel.Composition.ExportServices.CreateSemiStronglyTypedLazy(System.ComponentModel.Composition.Primitives.Export) (Strategy type CompositionLifetimeStrategy, index 2)
Microsoft.Practices.Unity.ResolutionFailedException
Resolution of the dependency failed, type = "MefContrib.Integration.Unity.Tests.Helpers.IUnityComponent", name = "". Exception message is: The current build operation (build key Build Key[MefContrib.Integration.Unity.Tests.Helpers.UnityComponent1, null]) failed: System.ComponentModel.Composition.ExportServices.CreateSemiStronglyTypedLazy(System.ComponentModel.Composition.Primitives.Export) (Strategy type CompositionLifetimeStrategy, index 2)
ExternalExportProviderTests
MethodAccessException
MefContrib.Integration.Unity.Tests.Helpers.External.MefComponent2..ctor(MefContrib.Integration.Unity.Tests.Helpers.External.IExternalComponent)
MethodAccessException
MefContrib.Integration.Unity.Tests.Helpers.External.MefComponent1..ctor(MefContrib.Integration.Unity.Tests.Helpers.External.IExternalComponent)
FullIntegrationTests
Microsoft.Practices.Unity.ResolutionFailedException
Resolution of the dependency failed, type = "MefContrib.Integration.Unity.Tests.Helpers.IUnityOnlyComponent", name = "". Exception message is: The current build operation (build key Build Key[MefContrib.Integration.Unity.Tests.Helpers.UnityOnlyComponent1, null]) failed: System.ComponentModel.Composition.ExportServices.CreateSemiStronglyTypedLazy(System.ComponentModel.Composition.Primitives.Export) (Strategy type CompositionLifetimeStrategy, index 2)
Microsoft.Practices.Unity.ResolutionFailedException
Resolution of the dependency failed, type = "MefContrib.Integration.Unity.Tests.Helpers.IMefComponentWithUnityDependencies", name = "". Exception message is: The current build operation (build key Build Key[MefContrib.Integration.Unity.Tests.Helpers.IMefComponentWithUnityDependencies, null]) failed: System.ComponentModel.Composition.ExportServices.CreateSemiStronglyTypedLazy(System.ComponentModel.Composition.Primitives.Export) (Strategy type CompositionLifetimeStrategy, index 2)
Microsoft.Practices.Unity.ResolutionFailedException
Resolution of the dependency failed, type = "MefContrib.Integration.Unity.Tests.Helpers.IMefComponentWithUnityDependencies", name = "component2". Exception message is: The current build operation (build key Build Key[MefContrib.Integration.Unity.Tests.Helpers.IMefComponentWithUnityDependencies, component2]) failed: System.ComponentModel.Composition.ExportServices.CreateSemiStronglyTypedLazy(System.ComponentModel.Composition.Primitives.Export) (Strategy type CompositionLifetimeStrategy, index 2)
Microsoft.Practices.Unity.ResolutionFailedException
Resolution of the dependency failed, type = "MefContrib.Integration.Unity.Tests.Helpers.UnityComponent2", name = "". Exception message is: The current build operation (build key Build Key[MefContrib.Integration.Unity.Tests.Helpers.UnityComponent2, null]) failed: System.ComponentModel.Composition.ExportServices.CreateSemiStronglyTypedLazy(System.ComponentModel.Composition.Primitives.Export) (Strategy type CompositionLifetimeStrategy, index 2)
UnityExportProviderTests
Microsoft.Practices.Unity.ResolutionFailedException
Resolution of the dependency failed, type = "MefContrib.Integration.Unity.Tests.Helpers.IUnityOnlyComponent", name = "unityComponent2". Exception message is: The current build operation (build key Build Key[MefContrib.Integration.Unity.Tests.Helpers.UnityOnlyComponent2, unityComponent2]) failed: Could not load type 'MefContrib.Integration.Unity.Tests.Helpers.UnityOnlyComponent2' from assembly 'MefContrib.Integration.Unity.Silverlight.Tests, Version=0.7.0.0, Culture=neutral, PublicKeyToken=null'. (Strategy type BuildPlanStrategy, index 3)
Microsoft.Practices.Unity.ResolutionFailedException
Resolution of the dependency failed, type = "MefContrib.Integration.Unity.Tests.Helpers.IUnityOnlyComponent", name = "". Exception message is: The current build operation (build key Build Key[MefContrib.Integration.Unity.Tests.Helpers.UnityOnlyComponent1, null]) failed: Could not load type 'MefContrib.Integration.Unity.Tests.Helpers.UnityOnlyComponent1' from assembly 'MefContrib.Integration.Unity.Silverlight.Tests, Version=0.7.0.0, Culture=neutral, PublicKeyToken=null'. (Strategy type BuildPlanStrategy, index 3)

AssertFailedException

Assert.AreEqual failed. Expected:<Returned Unity instance is null.>. Actual:<Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "MefContrib.Integration.Unity.Properties.Resources.resources" was correctly embedded or linked into assembly "MefContrib.Integration.Unity" at compile time, or that all the satellite assemblies required are loadable and fully signed.>.

 

Cheers

Adam

Coordinator
Nov 24, 2009 at 10:20 PM
Edited Nov 24, 2009 at 10:22 PM

Thank you for making an effort to put MEF Contrib into the Silverlight world. The tests were failing because the stub classes used throughout the tests were declared as internal not as public. Not sure why, MEF - SL has some problems with creating instances of internal classes.

If anyone is still interested in the SL port of MEF Contrib, I did it myself, it is briefly described on my blog at http://pwlodek.blogspot.com/2009/11/mef-contrib-for-silverlight-3.html, link to the source code is provided at the end of the post.

I think the future releases of the MEF Contrib project will be available for both the regular CLR and Silverlight.

 

Regards,

Piotr

Coordinator
Nov 24, 2009 at 10:21 PM
Nice one Piotr!

On Tue, Nov 24, 2009 at 11:20 PM, pwlodek <notifications@codeplex.com> wrote:
Piotr