Prism / Mef Directory Catalog SatisfyImports - prism

In my app I have a module that I have been referencing direct from the shell (just while I get things working).
i.e.
protected override void ConfigureAggregateCatalog()
{
base.ConfigureAggregateCatalog();
AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly));
AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(MyModule).Assembly));
}
In my module when I've been calling SatisfyImportsOnce for a view this has worked and I can see the view model etc being created.
However, I have now changed my bootstrapper to use a directoryCatalog for my module. I have added some post build events to copy my module assembly, pdb etc to the shell.
So now I have the following in my bootstrapper
protected override void ConfigureAggregateCatalog()
{
base.ConfigureAggregateCatalog();
AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly));
// add the directory catalog for the modules
AggregateCatalog.Catalogs.Add(new DirectoryCatalog("Modules"));
}
I am now able to run my app and see the views from my module but the SatisfyImportsOnce that used to work now seems to do nothing. I can't see any errors. Are there different attributes I need on my imports / exports now that I'm using the directory catalog?
Thanks.

No, there shouldn't be any difference in the attributes you need to use.
It's hard to tell what's wrong, here's a blog post on general MEF debugging.

Related

Is there a simple way to auto register [Exports] in a Prism app? WPF .NET 4.8

I used to be on a project that used Prism and when we needed a new service to do something, we'd just create an interface, a concrete class that implemented that interface and exported it, and then it just became available everywhere for [ImportingConstructor]. We didn't need to manually register it or anything. I no longer have access to that project, but I don't think there was any reflection magic that was done manually to accomplish this.
I'm in a new company and we are starting up a project using MEF / Prism and I'm trying to accomplish the same thing, but as of right now, I'm having to manually register items in order to import them. What am I missing?
I'm in .NET 4.8 WPF app
Additional info
we are basing our project from this website
https://prismlibrary.com/index.html
This is our app class
public partial class App
{
protected override Window CreateShell()
{
return Container.Resolve<ShellWindow>();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterSingleton<IStartupActionService, StartupActionService>();
containerRegistry.RegisterSingleton<IGeneralNavigationService, GeneralNavigationService>();
containerRegistry.RegisterSingleton<IExperimentSetupNavigationService, ExperimentSetupNavigationService>();
containerRegistry.RegisterSingleton<IProtocolSetupNavigationService, ProtocolSetupNavigationService>();
containerRegistry.RegisterSingleton<IOurProjectNavigationService, OurProjectNavigationService>();
containerRegistry.RegisterSingleton<IOurProjectUiService, OurProjectUiService>();
containerRegistry.RegisterManySingleton<WcfClientService>();
containerRegistry.RegisterSingleton<IControlClientService, ControlClientService>();
}
}
Why do I have to register each new service?
I've been reading about MEF, DryIoc, and others and I'm just not getting clear answers. Is there not a way to just have everything with an [Export] become immediately available for import?
Something else I need to do, that I think this whole registering thing is messing me up on is trying to come up with a way to have "dialogs" but tie them to a neutral class to make it more MVVM happy.
Dialog -> a region that pops open when you call a method. This method currently takes in a UserControl, assumed to have already been constructed and its ViewModel datacontext already attached.
What I would like to do and don't know how to start is
use a neutral container class to open one of these dialogs (similar to interaction request Notification
using attributes, attach an attribute to a view that indicates "I support this neutral container class" (assumed only one view per container)
this view supports [ImportingConstuctor] to bring in its ViewModel
the viewmodel itself supports [ImportingConstuctor] to bring in services needed
again, the desire to NOT need to register these items manually as we add them. Would like to add a service interface, the concrete class that [Export]s the interface and have it just available to the viewmodel and other services, and same for the views and viewmodels, export attribute tag them as necessary and have them just available to either/both grab an instance of them or manually create an instance of them and have their [ImportingConstructors] handled for me.

How to get Current Page/View or topmost Page/View in Xamarin.Forms

I want to show AlertDialog(DisplayAlert) in a Xamarin.Forms project when an unhandled error occurs.
How can I get the current page instance?
You need to keep a reference of your main page as you mentioned. There are a few ways to do this.
You can have a static reference to it in your App.cs file, which is actually already there as it inherits from Application which has:
App.Current.MainPage
If you use an MVVM helper like MVVMLight you pass the page to the service so it keeps a reference of it.
ACR UserDialogs is a dialog package that can also help as it extends and adds different types of dialogs
To get around this and have a lot more flexibility add 'ACR User Dialogs' package to each of your platform's projects.
Then you can use that from anywhere :
await UserDialogs.Instance.AlertAsync ("Your question has been successfully sent", "Thankyou");

Execute Code First Migrations is Grayed Out in Publish Settings

Using Windows Azure and attempting to publish my MVC3 Application. The check box for Execute Code First Migration in the settings panel of the Publish web application is grayed out. What changes do I need to make to be able to enable it?
I believe you see the following "Execute Code First Migration" disabled when you try to publish your MVC application:
This is potentially because either you do not full code written for Code migration in your application as well no or incorrect DB setup in your web.config as described here.
In order to have Code Migration enabled, you must have a DB configured (in case of Windows Azure you need to provide SQL Database info in the web.config) in web.config and a complete class is written on how the code migration will happen depend on your model. Here is an example on how to achieve it.
http://msdn.microsoft.com/en-us/library/dd394698#efcfmigrations
I am assuming that you have Entity Framework model and in your database already (if not then you need to do some reading, answer by #AvkashChauhan would be indeed a good starting point).
However if you do have a model and all the configurations like:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new YourEntityMap());
}
and all the entity mappings like:
public class YourEntityMap : EntityTypeConfiguration<YourEntity>
{
public YourEntityMap()
{
this.HasKey(t => t.Id);
}
}
and you still don't get the darn checkbox enabled you might want to do following steps:
Go to Tools > NuGet Package Manager > Package Manager Console
Then in console write
Enable-Migrations -ContextTypeName Company.Models.YourDevContext
where Company.Models.YourDevContext is your Database Context (look for class that inherits from DbContext should be same one that has OnModelCreating override).
after running command you should get something like:
At this point you should have Migrations folder added to the solution more on how to handle migrations here
Hope this saves you some time.

Magento override abstract block

I need to override an abstract Block in Magento : app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Options/Abstract.php
I need to add a function to this class similar as getOptionValues for a specific product type.
I tried to override by adding the same structure (folder creations and copy the Abstract.php file) in app/code/local/Mage/Eav/Block/Adminhtml/Attribute/Edit/Options/Abstract.php, but it seems not working.
Anyone can help me ?
Am I missing something ?
Do I need to create app/etc/modules XML or the app/code/local/Mage/Eav/etc XML ?
Thanks a lot !
In order to override the app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Options/Abstract.php
abstract class, you need to place the file as: app/code/local/Mage/Eav/Block/Adminhtml/Attribute/Edit/Options/Abstract.php
which means your local pool path for Abstract.php is correct.
The only thing that i doubt why it's not loading is: may be Compiler is enabled for your store(be sure to check from System > Tools > Compilation > Status should be Disabled).
Additionally check your log files(var/log/*.log) if there are any errors.
I would refer the following article for configuring your magento for development / debug mode:
http://www.blog.magepsycho.com/configuring-magento-for-development-debug-mode/
Hope this helps a bit.
Regards

I inherited a Magento project and can't seem to find this particular page?

I took over an implementation of Magento Enterprise.
There is a URL that looks something like this:
mydomain.com/our-solutions
It's got a dynamic part to it; under the CMS tab in the Admin I don't see anything that matches that URL.
In the extended local files, I don't see anything in the config for it but it seems to know to load up a particular template.
I need to be able to modify the controller for this particular page. Any advice would be great.
Thanks.
The quick and dirty way would be to temporarily add some debugging code to the following file
# File app/code/core/Mage/Core/Controller/Front/Action.php
public function preDispatch()
{
//log out the class name
Mage::Log( get_class($this) );
//or just dump it if you don't know how logging works
var_dump(get_class($this));
$this->getLayout()->setArea($this->_currentArea);
parent::preDispatch();
return $this;
}
This will let you discover which class file is the controller for the request, and you can code trace from there.
Also (shameless plug time) I build and sell a commercial product that will (among other things) allow you to (among other things) instantly zero in on which controller, block, model, or collection was used for a particular request. There's a demo page you can checkout, and while it's clearly self-serving of me to mention it, I also truly believe it's the best way for a developer to work with Magento.

Resources