Quantcast
Channel: Managed Extensibility Framework
Viewing all 265 articles
Browse latest View live

New Post: MEF2 with MVC4 via Microsoft.Composition


New Post: MEF2 with MVC4 via Microsoft.Composition

$
0
0

I've done something like that on my project (http://mefistonet.codeplex.com/).

In the sourcecode, you'll find a proof of concept (dev/V0/Mefisto4), where I use MEF and MVC4 together, allowing me to have some plugins, working without restarting the website.

The magic comes from my rewriting of the controller and view engines.

Just take a look when you'll have a moment ;)

 

arsenikstiger

New Post: Import visibility with MEFX

$
0
0

I'm trying to match imports and exports with mefx, using /exports and /imports.
I get missing imports in this situation:

Let's demonstrate with the most simple expample ever

namespace Example01
{
  p
ublicclassProgram
  {
   
publicclass MyClass
    {
      [
Import("MajorRevision")]
     
publicint MajorRevision { get;set; }
   
}    

      publicclassMyExportClass
    {
      [
Export("MajorRevision")]//This one will match.
      publicintMajorRevision = 4;

     [Export("MinorRevision")]
     
publicintMinorRevision = 16;
    }
  } 
}

Running my mefx commands gives these results

mefx /dir:Example01\bin\Debug /parts
Example01.MyExportClass

mefx /dir:Example01\bin\Debug /exports
MajorRevision : System.Int32
MinorRevision : System.Int32

mefx /dir:Example01\bin\Debug /imports

I get an empty line for "imports". Looking on internet for such problem, I found this article:
http://stackoverflow.com/questions/7810661/mefx-does-not-list-an-importer
But the response doesn't satisfy me. It's sayed "how", but not "why". I'm certainly missing something.

I tried what was explained doing this:

[Export]
publicclassMyClass
{
[
Import("MajorRevision")]
publicint MajorRevision { get;set; }
}

Now I get this result with mefx:

mefx /dir:Example01\bin\Debug /imports
MajorRevision : System.Int32.

I would expect this result without the export clause on MyClass. My application is resolving perfectly the parts without this "Export". It's not necessary. Why mefx needs this to see the import? I'm not ready to add unnecessary information in my code just for mefx.

New Post: Windows 8 MEF

$
0
0

Okay, I've looked all over and can't find anything in the samples.  Only thing I've been able to find regarding usage in Windows 8 is the blog posts about it being released on Nuget.  I've copied this code to my App.xaml.cs

var configuration = new ContainerConfiguration().WithAssembly(typeof(App).GetTypeInfo().Assembly);

I've confirmed that when my application starts that I can get instances of the exported classes while stepping through the debugger using 

_mefContainer = configuration.CreateContainer();
var viewModel = _mefContainer.GetExport<MainViewModel>();

 

However, when the default code in OnLaunched runs

if (!rootFrame.Navigate(typeof(MainView), args.Arguments))

It is not using an instance of the view from the container.  Here is the my view constructor with export and import attributes for the view model.

    [Export]
    publicsealedpartialclass MainView : Page
    {
        public MainView()
        {
            this.InitializeComponent();
        }

        [Import]
        public MainViewModel ViewModel 
        { 
            get
            {
                return _viewModel;
            }
            set
            {
                _viewModel = value;
                this.DataContext = value;
            }
        }
        private MainViewModel _viewModel;

Any ideas on what I'm doing wrong?  I've used MEF with Prism in an WPF appliaction before and had no problems with it so I'm familiar with how to set up the classes to correctly import and export objects.  I'm just stumped on how to correctly setup and use the container other than using GetExport<T> everytime - Is that how I'm supposed to do it?  Would be great to find a simple Win8 app sample that used MEF.

New Post: Windows 8 MEF

$
0
0

You need to do the GetExport on your View since that's what you're exporting. 

 

 

var mainView = _mefContainer.GetExport<MainView>();

...

if (!rootFrame.Navigate(typeof(mainView), args.Arguments))

 

I've got a sample project with MEF and trying to hook it up with Caliburn.Micro. You can see how MEF gets set up at least.

http://caliburnmicro.codeplex.com/discussions/399671

New Post: Windows 8 MEF

$
0
0

@iamdragonwolf: the Navigate code will not compile because "mainView" is not a type. 

New Post: Windows 8 MEF

$
0
0

Oh right, an instance doesn't work since the NavigationService wants to create the instance itself.

You could have the Frame created in your MainView and navigate from there if you need the navigation and then you can use

var mainView = _mefContainer.GetExport<MainView>();
Window.Current.Content = mainView;
Window.Current.Activate();

You're still stuck with pages not being pulled from a container, however, for navigation after MainView is loaded. 
I think with the default navigation being view-first, you'll have to create your own navigation to use with MEF or move to a viewmodel first approach.
Caliburn.Micro fits in nicely if you're going that route. You'll have to pull the latest source as there hasn't been a release of the Win8 changes yet.


New Post: Problems when using 2 CompositionContainers

$
0
0

Assembly's with identical Assembly Name's in separate CompositionContainers will cause problems.

My program has 2 CompositionContainer's filled from 2 directories.  However if an Assembly is in both directories and has the same 'assembly name' then a GetExportedValues() from the second CompositionContainer will return the dll from the first CompositionContainer.

Why is this and when will it be fixed?


New Post: Windows Phone 8?

$
0
0

We've recompiled the source (in oob\src) to include Windows Phone 8, and found the assemblies all compile cleanly. 

Can we distribute these assemblies with our product?  We'd prefer to use the supported version.  Do you plan to release a a new version supporting "web, Windows Store, and Windows Phone 8", and if so, when?

New Post: MEF2 with MVC4 via Microsoft.Composition

$
0
0

Hello,

I have just spent couple of hours trying to do some MVC4 + MEF2 (with parts defined in separate assembly), also agree with cmschick, lot of samples but there are not 2 working the same... and none of them working as expected with the environment I have.

Anyway I finally managed to have it working as expected, and here are my findings, just in case these could help someone.

Here is my setup:

I have a simple ASP MVC 4 web application, and I want to separate some functionality into a separate assembly with the scope of reusing them in other projects (e.g.  security infrastructure and access control at very granular level - buttons...fields and so on). I would use RazorGenerator in the external assembly to precompile the views.

The only configuration that worked properly for me and my use case is as following:

- I had to uninstall what I installed from NuGet because I got an error "Ambiguous....." every time I wanted to put the external assembly into the catalog, eventually I tracked the problem to the generated class of the view with RazorGenerator tool, I don't understood why that class would affect the composition it was not in a Part folder it was not tagged with Export attribute.

But then I observed that the binaries from NuGet had version 1.0.0.0 and the binaries that I obtained by compiling source code from CodePlex were 1.1.0.0 so I decided to uninstall the NuGet and use the binaries I had compiled.

With these binaries I had to use a different approach to configure the composition actually a pretty simple one:

publicstaticclassCompositionConfig
{ 
    publicstaticvoidRegisterComposition()
    
{
        var a = newAssembly[] { typeof(CompositionConfig).Assembly,typeof(IAuthService).Assembly };

 

        CompositionProvider.AddPartsAssemblies(a);
    

}
}

This way the composition container is properly set and I had no errors, the parts exported from the other assembly get injected properly also the precompiled Razor views works.

There is no need to create a custom controller factory, in the past I follow such an approach - I mean custom controller factory - (with MEF 1) but for some reasons the application was leaking a lot and I changed MEF 1 to an earlier version of MEF 2 (with MVC 3), and I got rid of leaks, so watch out if your parts get collected as expected when you are using custom controller factory.

 

 

 

New Comment on "DeploymentCatalog"

$
0
0
I'm getting this issue when I try to reload a xap file using DeploymentCatalog, the file is reloaded successfully but the re-composition seems to use the old version of the xap file. Here is the situation: I have a module called ModuleA.xap that is loaded when a button is clicked on UI. after the ModuleA.xap is loaded using DeploymentCatalog a list is populated with data that comes from a service defined within ModuleA.xap. the service has property called Version [String] that's shows on UI. A updated Module.xap package and assigned a new value for Version property. I clicked the button to reload ModuleA.xap. After recomposition I still see the old value for Version property. !!!!!! Through Chrome I see that a request is made and the updated version of ModuleA.xap is loaded. but when I change the assembly version re-composition fails !!!!!!! -Hamid

New Post: Reloading an updated version of XAP through DeploymentCatalog does not recompose correctly

$
0
0

DeploymentCatalog does not seem to consume the proper version of XAP package.

in fact when the application start and an extension (xap package) is loaded the first time composition works fine, but if I drop a newer version of the xap package and try to reload it the re-composition seems the produce the same old result.

do DeployementCatalog use a cached version of the xap package ?

I inspected through Chrome and I saw a request is made to load the new version, however when I changed the version of the assemblies in the package re-composition failed with "Object reference set to null" !!!!!

New Post: MEF2 with MVC4 via Microsoft.Composition

New Post: Convention-based export with attribute-based metadata

$
0
0

Hello, I'd like to use RegistrationBuilder to export all derived types:

rb.ForTypesDerivedFrom<IFoo>().Export<IFoo>();

I need to have an ability to apply metadata individually at class level:

    [ExportMetadata("Name", "boo")]publicclass Foo1 : IFoo
    {
    }

The way of importing parts is:

    [ImportMany]public IEnumerable<Lazy<IFoo, IFooMeta>> foos;

No parts are discovered, because of lack of metadata. I've read how attributes overwrite convention-based info - link. However, it'd require adding an explicit ExportAttribute to each "Foo" class as well. Then, there is no point in having a RegistrationBuilder.

While I seem to understand the reasoning behind this design, my needs definitely fit in a convention - all classes implementing IFoo should be exported with their metadata. One work-around I can think of is:

 

rb.ForTypesDerivedFrom<IFoo>().Export<IFoo>().AddMetadata("Name", retrieveMetaFunc);

where retrieveMetaFunc is a custom method that extracts required metadata from a type. I'm in search for a cleaner, built-in approach that'd eliminate the need for repetitive ExportAttributes on every class definition. For the sake of example something like this:

rb.ForTypesDerivedFrom<IFoo>().Export<IFoo>().WithMetadata();
Notice I'm not able to use custom export attributes, because I have multiple IFooMeta on each exported part.

 

 

Created Issue: Missing Component DeploymentCatalog [14602]

$
0
0
I moved some code from the 4.0 framework to the 4.5 framework and the object System.ComponentModel.Composition.Hosting.DeploymentCatalog doesn't exist anymore.

New Post: Correct behavior

$
0
0

Hi

I'm using MEF as my view model container.

I have public property in view model called for example test, when I assign her outside the constructor, property is always 0. When I assign them in construcor of object everythings fine.

Why when I assign value to property outside of constructor I see the default value of property when calling getexportedvalue of this view model ?

 

Thanks in advance !

Commented Issue: Missing Component DeploymentCatalog [14602]

$
0
0
I moved some code from the 4.0 framework to the 4.5 framework and the object System.ComponentModel.Composition.Hosting.DeploymentCatalog doesn't exist anymore.
Comments: I copied the older DLLs from another project and now I get this error: {System.IO.FileNotFoundException: Could not load file or assembly 'System.Threading.Tasks, Version=2.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. File name: 'System.Threading.Tasks, Version=2.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'} When I new up a Deployment Catalog. The version in the GAC is 4.0.0.0. The code is simple: aggregateCatalog = new AggregateCatalog(); aggregateCatalog.Catalogs.Add(new DeploymentCatalog()); Any idea on what to do?

New Post: Windows Phone 8?

$
0
0

Did the same thing, as simple as checking support for Windows Phone 8, as well as Windows Store app and .NET 4.5, for each of the five projects. Can you please create a new release with this WP8 support built-in to the PCL assemblies?!

Created Issue: WP8 support missing in PCL assemblies! [14603]

$
0
0
Since Windows Phone 8 is not checked as supported target framework in the MEF portable class libraries (currently only .NET for Windows Store apps and .NET Framework 4.5), it will only work in emulator and not on a physical device. So in order to be able to share code between WinRT and WinPRT you have to rebuilt the MEF source yourself, with added support for WP8.

Since the solution is as simple as that I hope there will be a release very soon, with common PCLs targeting all of the above, thus enabling shared assemblies between Windows Store apps and Windows Phone 8 apps for example.

New Post: Windows Phone 8?

Viewing all 265 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>