MvvmCross registering interfaces using IoC in Xamarin iOS7 and XCode 5 - xamarin.ios

I'm having an issue activating the IMvxMessenger using IoC. (Mac, Xamarin Studio, iOS7, Mono 3.2)
I have downloaded NPlus1DaysOfMvvmCross and loaded the N37 Maps project.
Compiled the project and it works fine.
I then added the Cirrious.MvvmCross.Plugins.Messenger.dll to the project and the following code to the app.cs Initialize just below the service IoC call.
CreatableTypes (typeof(IMvxMessenger).Assembly).AsInterfaces ().RegisterAsSingleton ();
I receive and error when compiling that says:
Failed to resolve parameter for parameter id of type Guid when creating Cirrious.MvvmCross.Plugins.Messenger.MvxSubscriptionToken

IMvxMessenger is a plugin and does not need to be registered for IoC in the way you are doing it. Plugins get registered by creating a bootstrap class for each of the plugins you want to use in your project like so:
public class MessengerPluginBootstrap
: MvxPluginBootstrapAction<Cirrious.MvvmCross.Plugins.Messenger.PluginLoader>
{
}
Some plugins with platform dependent parts, such as the Visibility Plugin, need to be registered in a different manner on iOS, because it is silly:
public class VisibilityPluginBootstrap
: MvxLoaderPluginBootstrapAction<Cirrious.MvvmCross.Plugins.Visibility.PluginLoader, Cirrious.MvvmCross.Plugins.Visibility.Touch.Plugin>
{
}
This way you should be able to use the types inside of the Plugin using IoC.

This doesn't sound like it's anything to do with ios7
The line of code
CreatableTypes(typeof(IMvxMessenger).Assembly)
.AsInterfaces()
.RegisterAsSingleton ();
will:
take all the creatable types in the assembly (ie any non-abstract types with a public constructor)
will then find their interfaces
will then create a new instance and register that as the singleton implementation for the interfaces.
For the Messenger plugin, that includes trying to new and register an MvxSubscriptionToken as an IDisposable singleton - although this fails as the public constructor for MvxSubscriptionToken requires a Guid (and you haven't told MvvmCross how to supply that - so the construction fails)
If you did want to just register specific types in an Assembly, then normally you'd add a EndingWith("PostFix") clause - like the default Mvx nuget templates do with Services as the postfix.
If you did want to just register a single specific class from an Assembly, then you'd often just do that as:
Mvx.RegisterSingleton<IThing>(new Thing());
However, for plugins - which are just a convention-based set of rules placed on top of IoC - what you normally want to do is to call EnsureLoaded() on the plugin manager for the PluginLoader for that plugin.
The easiest way to do that is to include a Bootstrap file in the UI project - see the examples in N=8 - https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-09-Location%20And%20Message/Location.Touch/Bootstrap - your application's Setup will use Reflection to find that Type and will then call EnsureLoaded on the plugin for you.
For more on IoC in MvvmCross, see https://github.com/slodge/MvvmCross/wiki/Service-Location-and-Inversion-of-Control
For more on plugins, see https://github.com/slodge/MvvmCross/wiki/MvvmCross-plugins

Make sure the plugin is installed in the Core project AND the Android project.

Related

How to override UserLocalServiceImpl in liferay 7 without service wrapper?

I created service wrapper for UserLocalServiceImpl and declared a new method inside the service wrapper. But when I explicitly call that method using UserLocalServiceUtil the compiler could not resolve this method. So, kindly help me and tell how to override UserLocalServiceImpl so that I can define new methods inside it. Thanx in advance..
This doesn't work. You'd change the interface of Liferay's published API and basically be incompatible with any other plugin that assumes Liferay's API.
While you technically have access to all of Liferay's source code and can build a modified version of Liferay, introducing this change, it would mean that no marketplace plugin (that uses UserLocalService) would be compatible with your customized version. Any OSGi component can hook into Liferay and get into the callstack for the published API, no OSGi plugin can extend a published interface so that the original interface then has more methods than Liferay's published API.
The best thing you can do if you rely on a separate function call: Create your custom service that makes calls to UserLocalService.
Further more, in Liferay 7 you shouldn't use UserLocalServiceUtil any more, rather get the service dependency properly injected through a #Reference annotation. The *LocalServiceUtil classes are there purely for backwards compatibility and to be used only from *.WAR style plugins.
You can do
UserLocalServiceUtil.getService()
and then cast the result to your custom wrapper type. Then you should be able to call the new method.

MonoTouch Binding library built using Objective-C static library doesn't call corresponding objective-C method when C# counterpart is called

I've a static library (say myLibrary.a) built from Objective-C Xcode project.
I'm trying to re-use it in Mono Touch iOS application. Following documentation, I built an iOS library project in Xamarin Studio, added myLibrary.a and linked and exported all the methods I want to be available using MyLibrary.cs as shown below. When I build the project it produces myLibrary.dll
[BaseType (typeof (NSObject))]
interface TouchTestDriver {
[Static]
[Export ("initMyLibrary")]
void InitMyLibrary ();
[Static]
[Export ("startDoingSomethingInteresting:")]
NSUrl StartDoingSomethingInteresting (NSUrl url);
}
Then I built an iOS app (solution) using Xamarin Studio, and included myLibrary.dll in the resources. The classes from myLibrary.dll are visible, so I could do something like this:
using MyLibrary;
and in AppDelegate.cs FinishedLaunching() method, I call the method
MyLibraryLib.MyLibrary.InitMyLibrary();
When the app is run in Simulator, it all seems to work fine, but its not calling the objective-C method initMyLibrary(). I confirm this by putting NSLog(), and exit(0). The app doesn't log anything not does it exit.
Am I missing anything? Is there any documentation for this usecase (other than the BindingSample, which I have followed several times w/o any success)

Dynamics CRM 2011 - Does each plugin that related to a different entity have to have it's own assembly?

I am creating a series of related plugins. Each plugin is for a different entity. Does each plugin have to have it's own assembly? I'm using Visual Studio and I created a second project within the same solution but I can't see the new step in registration tool.
Thanks
It can do, but doesn't have to. That is pretty much your design decision. Consider if you had several classes all implementing IPlugin
public class MyFirstPlugin : IPlugin
{
//implemented as per usual
}
public class MySecondPlugin : IPlugin
{
//implemented as per usual
}
If you were to register that DLL in the plugin registration tool, you would see the following structure:
- Server
- DLL
- MyFirdtPlugin
- MySecondPlugin
You can then add steps to each plugin as desired.
The alternative would be to have one plugin per DLL, which would give you
- Server
- DLL1
- MyFirstPlugin
- DLL2
- MySecondPlugin
I must admit it seems like overkill - but it can also depend on how you are using your solutions.
In addition to glosrob's answer, I'm guessing that you're using the plugin registration tool to register your plugin. If so, you'll need to make sure that after you add your new plugin to the same dll, that you update the plugin dll itself with the registration tool, so you can register the new plugin method that you've created.
Yes, you can create each plugin in a different class library project but this is not a good practice. I'd prefer to collect all plugins into one class library.
Note that after selecting your assembly from the File Dialog you have to click on Load Assembly button to load all classes which implement the IPlugin interface.
To answer the question - no, each new plugin doesn't have to be contained in a new assembly.
To elaborate - it's technically possible to put in all the plugin code in just one project and a single file.
To warn - the above would be a nightmare to manage with all the ifs and buts, so it's a good example of can-but-shouldn't.
To suggest - I usually have a separate project for each entity's plugin and handle all the messages using a switch. On occasion, I might have two or three assemblies but you'll know when it's time to do so as you get there. Usually, one DLL is just enough.

Automapper : Automating Profile registration not using global.aspx

I am using AutoMapper in a distributable C# DLL for my ORM logic.
This DLL is consumed by different development teams for the web projects. Some of these web projects are MVC and some are web forms.
If there a way to have my DLL ensure that all the mappings have been register on application-start without having each team put the calls in their global files?
I have profiles all setup, but want this step to be hidden and always done.
Thanks
The only thing I can think of is to have a static constructor for a class in your dll where you will initialize automapper.
public class MyOrmClass
{
public static MyOrmclass()
{
//initialize automapper
}
}
I have an open source library that might help you with it, but you might have to do some small changes on each client

using CustomActionAttribute in System.Configuration.Install.Installer classes

Can I use CustomActionAttribute in classes that inherit from System.Configuration.Install.Installer? I want my class library to support both WiX and Visual Studio setup project.
I don't see any immediate reason why you couldn't do this. One obstacle is that Wix managed CA functions must be declared public static, so you would probably need to refactor most of your logic into functions that could be called by both your Install/Uninstall functions as well as your Wix CAs functions.
If you were to do this I would recommend creating the project from the Votive Managed Custom Action template in Visual Studio and then manually adding a Installer Class to the project. You can then define static functions in the installer class that can be exposed as CAs using the CustomAction attribute.
The reasons for not doing it are:
you can't have methods with same names in your custom actions assembly custom action method calls in WiX
And the DTF methods and VS setup project methods are different in signature.
Also, as I've understood, VS setup project CAs don't use Session object, unlike DTF CAs.

Resources