I get a resolve error when I try to inject into a FSharp library but not wen I do so with a CSharp library.
I have 3 projects :
- A main application in csharp
- A CSharp project containing a class whose constructor requires a IUnityContainer that gets instantiated fine
- A FSharp project containing a class whose constructor requires a IUnityContainer that can't instantiate with error
Resolution of the dependency failed, type = "ModuleDBGraphFS.ModuleEntityGraphFS", name = "(none)". Exception occurred while: while resolving. Exception is: InvalidOperationException - The current type, Microsoft.Practices.Unity.IUnityContainer, is an interface and cannot be constructed. Are you missing a type mapping?
At the time of the exception, the container was:
Resolving ModuleDBGraphFS.ModuleEntityGraphFS,(none) Resolving parameter "container" of constructor ModuleDBGraphFS.ModuleEntityGraphFS(Microsoft.Practices.Unity.IUnityContainer container, Microsoft.Practices.Prism.Regions.IRegionManager manager) Resolving Microsoft.Practices.Unity.IUnityContainer,(none)
Application class in the 1st project (WPF project, you add prism, remove the startupuri from app.xaml, add on the code behind for the bootstrapper )
namespace WpfApplication
{
class Bootstrapper : UnityBootstrapper
{
protected override DependencyObject CreateShell()
{
return this.Container.Resolve<Shell>();
}
protected override void InitializeShell()
{
base.InitializeShell();
App.Current.MainWindow = (Window)this.Shell;
App.Current.MainWindow.Show();
}
protected override void ConfigureModuleCatalog()
{
base.ConfigureModuleCatalog();
ModuleCatalog moduleCatalog = (ModuleCatalog)this.ModuleCatalog;
// OK moduleCatalog.AddModule(typeof(ModuleDBGraph.ModuleEntityGraph));
// KO moduleCatalog.AddModule(typeof(ModuleDBGraphFS.ModuleEntityGraphFS));
}
}
}
In the C# project
public class ModuleEntityGraph : IModule
{
private IUnityContainer _container;
private readonly IRegionManager _manager;
public ModuleEntityGraph(IUnityContainer container, IRegionManager manager)
{
_container = container;
_manager = manager;
}
void IModule.Initialize()
{
}
}
in the F# project
type ModuleEntityGraphFS(container:IUnityContainer, manager:IRegionManager) =
do printfn "hi"
interface Microsoft.Practices.Prism.Modularity.IModule with
member x.Initialize() =
do ()
IUnityContainer
mapping setup. – Guvante