Registering custom region adapters in MefBootstrapper

Topics: Prism v4 - Silverlight 4
Nov 17, 2010 at 10:14 AM

Hi,

I need to register 2 custom region adapters in the ConfigureRegionAdapterMappings in my MefBootstrapper. I couldnt find a way to do it yet anywhere. How do we do it?

Cheers!

ConfigureRegionAdapterMappings

Nov 17, 2010 at 7:07 PM

Hi,

For achieving this scenario, it is necessary to override the ConfigureRegionAdapterMappings method in your Bootstrapper to add your own custom region adapter mappings. That said, your code might be similar to the following:

protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
{
RegionAdapterMappings mappings = base.ConfigureRegionAdapterMappings();
mappings.RegisterMapping(typeof(ControlToAdapt1), new CustomRegionAdapter1());
mappings.RegisterMapping(typeof(ControlToAdapt2), new CustomRegionAdapter2());
return mappings;
}

Hope this helps.

Fernando Antivero
http://blogs.southworks.net/fantivero

 

Nov 23, 2010 at 7:50 AM

Hi Fernando,

The problem is I cannot do a new CustomRegionAdapter() as it needs a IRegionBehaviourFactory in its constructor. I was thinking of putting a Export tag on the CustomRegionAdapter and adding to the AggregateCatalog. And then I can fetch it from the Container like below.

[Export]
public class CustomRegionAdapter : RegionAdapterBase<Grid>
{
}

And then in the ConfigureAggregateCatalog

protected override void ConfigureAggregateCatalog()
{
            base.ConfigureAggregateCatalog();

            AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(CustomRegionAdapter).Assembly));
}

And then in the ConfigureRegionAdapters

protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
{
            var mappings = base.ConfigureRegionAdapterMappings();
           mappings.RegisterMapping(typeof(Grid), Container.GetExportedValue<CustomRegionAdapter>());
return mappings;
}

Would this not work?

Nov 23, 2010 at 2:27 PM

Hi,

It seems to be a possible approach for achieving your scenario. Please take into account that if your Custom Region Adapter has to be created using a non-default constructor, you will need to specify to the composition engine the constructor that you want use by decorating it with the ImportingContructor attribute. So your code might be similar to the following:

[Export]

public class CustomRegionAdapter : RegionAdapterBase<Grid>
{
  [ImportingConstructor]    
public void CustomRegionAdapter (IRegionBehaviourFactory regionBehaviourFactory)
}

This way the the IRegionBehaviorFactory is declarer automatically. For more information on this topic, you could take a look at the following documentation section on MSDN: Attributed Programming Model Overview, see the Prerequisites Imports section.

Hope this helps.

Fernando Antivero
http://blogs.southworks.net/fantivero

 

Nov 23, 2010 at 2:32 PM
Yes. You are right. I missed that out. I guess rest should work then.

Thanks.


From: fantivero <notifications@codeplex.com>
To: Shivshankar, Ganesh (IT/IN)
Sent: Tue Nov 23 20:57:51 2010
Subject: Re: Registering custom region adapters in MefBootstrapper [CompositeWPF:235004]

From: fantivero

Hi,

It seems to be a possible approach for achieving your scenario. Please take into account that if your Custom Region Adapter has to be created using a non-default constructor, you will need to specify to the composition engine the constructor that you want use by decorating it with the ImportingContructor attribute. So your code might be similar to the following:

[Export]

public class CustomRegionAdapter : RegionAdapterBase<Grid>
{
  [ImportingConstructor]    
public void CustomRegionAdapter (IRegionBehaviourFactory regionBehaviourFactory)
}

This way the the IRegionBehaviorFactory is declarer automatically. For more information on this topic, you could take a look at the following documentation section on MSDN: Attributed Programming Model Overview, see the Prerequisites Imports section.

Hope this helps.

Fernando Antivero
http://blogs.southworks.net/fantivero

Read the full discussion online.

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

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

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe 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

This e-mail (including any attachments) is confidential, may contain
proprietary or privileged information and is intended for the named
recipient(s) only. Unintended recipients are prohibited from taking
action on the basis of information in this e-mail and must delete all
copies. Nomura will not accept responsibility or liability for the
accuracy or completeness of, or the presence of any virus or disabling
code in, this e-mail. If verification is sought please request a hard
copy. Any reference to the terms of executed transactions should be
treated as preliminary only and subject to formal written confirmation
by Nomura. Nomura reserves the right to monitor e-mail communications
through its networks (in accordance with applicable laws). No
confidentiality or privilege is waived or lost by Nomura by any
mistransmission of this e-mail. Any reference to "Nomura" is a
reference to any entity in the Nomura Holdings, Inc. group.
Please read our Electronic Communications Legal Notice which forms
part of this e-mail: http://www.Nomura.com/email_disclaimer.htm