Prism Xamarin.Forms 依赖注入构造函数参数
Prism Xamarin.Forms dependency injection constructor parameters
我正在使用 Xamarin.Forms 和 Prism。我正在使用棱镜提供的依赖注入。 (也注入我自己的实例 类,不仅是特定于平台的)
我的问题是如何在依赖注入中将参数传递给构造函数?
谢谢
您通常不会通过构造函数传递参数。您只需注入 class 依赖项,例如服务。要注入您的服务,只需在 App.cs
中的 RegisterTypes 方法中向容器注册它们
假设您使用的是 Unity:
Container.RegisterType<IMyService, MyService>(optionally make it a singleton)
我正在使用 Xamarin.Forms 和 Prism。我正在使用棱镜提供的依赖注入。 (也注入我自己的实例 类,不仅是特定于平台的)
我的问题是如何在依赖注入中将参数传递给构造函数?
谢谢
您通常不会通过构造函数传递参数。您只需注入 class 依赖项,例如服务。要注入您的服务,只需在 App.cs
中的 RegisterTypes 方法中向容器注册它们假设您使用的是 Unity:
Container.RegisterType<IMyService, MyService>(optionally make it a singleton)