Create AutoMapper modules like Ninject modules? - automapper

It is possible to create automapper like modules (such thoses of ninject) so i can define my mappings from an external library here and include them in a bootstrap class ?

That is exactly what Bootstrapper does. All you have to do is implement IMapCreator and Bootstrapper will find and execute your mapping code at startup time.

Related

Custom class libraries in Typescript

I'm trying to figure out the best way to write a class library in Typescript and deploy it to NPM with a definitions file.
The classes in the library are essentially models that are shared across our various RESTful services. Some of them have a few utility functions.
In my current process, I've created a single module where all of the classes can be accessed from (index.js). And then I manually maintain a .d.ts that has all of the class and interface definitions. Any time I make a change to the actual implementation, I must remember to also update the definition file.
When I deploy to our private NPM server, I only deploy the the transpiled .js files and the definitions file. Services that install my npm package just need to add a single /// <reference path="..." /> to their references file.
This works; it's just cumbersome and error-prone. Is there a decent/easy way for me to generate a single definitions file automatically from all of the classes I have? If not, is there something different I can/should do to share common Typescript modules across projects?
All you have to do is add --declaration to your compiler options and it will create the corresponding d.ts file/s for you. No need to do that manually.

MVC Ninject: How to add NinJect bindings from an MVC Area project

I've been using this blog example:
http://blog.longle.net/2012/03/29/building-a-composite-mvc3-application-with-pluggable-areas/
I have the concepts working in my solution. However, I'm trying to figure out a good way only add bindings to the kernel if a user has permissions to access a module/area.
I've read up some on the ServiceLocator but I was trying to stay away from it.
One thing I'm trying just to get things to work is user Contructor injection in the default constructor for a module. It's working but is a hack.
The pattern I'm using, each module project you create an class that inherits from AreaRegistion. When each module project builds, relevant files are copied to the Areas folder of the main web project. Then when the main project loads, reflection is used to load all module assemblies. Then when AreaRegistration.RegisterAllAreas() is called, it detects and loads all the modules with a class that inherits AreaRegistration.
I'd like to figure out an good way to access the Ninject kernel and add bindings in the module class that inherits from AreaRegistration. I would imagine initiating code to add bindings from the RegisterArea() override.
I'm looking for any suggestions on how to do this without resorting to the ServiceLocator.
Any ideas would be greatly appreciated.
For now I've found a better solution and that's to use NinjectModule. In the Plugin class, I'm going to create a class which inherits from NinjectModule. Then setup the pluging bindings in the Load overload.
Then use Kernel.Load in my main app bootstrapper to initialize the Load overloads in all plugin classes which inherit from NinjectModule.

MvvmCross registering interfaces using IoC in Xamarin iOS7 and XCode 5

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.

Override class at runtime

in C# assembly under my control is a class. I control creating all its instances. How can I override its constructor, all methods and properties at runtime? How can I create an instance of this overriden class?
Look for dependency Injection framework: Unity, Ninject, Castle Windsor framework.
I used reflection to create a code and compiled it by CSharpCodeProvider.

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