私はこのようにコンストラクタインジェクションを試みました:
public partial class MainPage : PhoneApplicationPage
{
private readonly ISomeService service;
public MainPage(ISomeService service)
{
InitializeComponent();
this.service = service;
}
}
App.xaml.csコンストラクターで:
public App()
{
// Global handler for uncaught exceptions.
UnhandledException += Application_UnhandledException;
DependencyService.Initialize(GetAssemblyFilePathCollection());
DependencyService
.Container
.Register(typeof(MainPage), made: Made.Of(() => new MainPage(Arg.Of<ISomeService>())));
// The remaining part is omitted.
}
DependencyServiceContainerを作成し、すべてのアセンブリからバインディングをロードする カスタム静的クラスです。
この場合、App.RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)メソッドは常に実行されます。
e.ExceptionはSystem.MissingMethodExceptionメッセージ付きですNo parameterless constructor defined for this object.e.Uriとしてファイル/MainPage.xamlで宣言されています。WMAppManifest.xmlNavigationPage
コンストラクター内ではMainPage、コンテナーを直接使用してサービスを正常に解決できますが、コンストラクター注入を使用したいと考えています。
これに関する具体的な例は見つかりませんでした。誰でもそれがどのように機能するか考えていますか?