gpt4 book ai didi

f# - 团结, Prism ,FSharp

转载 作者:行者123 更新时间:2023-12-05 01:20:55 26 4
gpt4 key购买 nike

当我尝试注入(inject) FSharp 库时出现解析错误,但在使用 CSharp 库时却没有。

我有 3 个项目:

  • csharp 中的主要应用
  • 一个 CSharp 项目包含一个类,该类的构造函数需要一个 IUnityContainer,该 IUnityContainer 可以很好地实例化
  • 一个 FSharp 项目包含一个类,该类的构造函数需要一个 IUnityContainer,该 IUnityContainer 无法实例化并出现错误

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)

第一个项目中的应用程序类(WPF 项目,您添加 prism,从 app.xaml 中删除 startupuri,为 Bootstrap 添加后面的代码)

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));
}
}
}

在C#项目中

public class ModuleEntityGraph : IModule
{
private IUnityContainer _container;
private readonly IRegionManager _manager;

public ModuleEntityGraph(IUnityContainer container, IRegionManager manager)
{
_container = container;
_manager = manager;
}

void IModule.Initialize()
{
}
}

在F#项目中

type ModuleEntityGraphFS(container:IUnityContainer, manager:IRegionManager) =
do printfn "hi"
interface Microsoft.Practices.Prism.Modularity.IModule with
member x.Initialize() =
do ()

最佳答案

出于某种原因,prism 的 Nuget 脚本在我的模块项目中添加了对

的引用
C:\windows\assembly\GAC_MSIL\Microsoft.Practices.Unity\1.2.0.0__31bf3856ad364e35\Microsoft.Practices.Unity.dll

虽然shell项目本身正在引用

WpfApplication3\packages\Unity.2.1.505.2\lib\NET35\Microsoft.Practices.Unity.dll

我开始的一个新的解决方案让我看到了问题。因此,奇怪的消息是它无法解析 UnityContainer 本身(应该通过 Prism Unity 扩展在某处注册....)

关于f# - 团结, Prism ,FSharp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15442189/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com