私のNinjectコンストラクトに問題があります。誰かが私が間違っているところを教えてくれるかもしれません..
わかりました..ここに私が持っているモジュールがあります:
public class WebPageModule:NinjectModule
{
public override void Load()
{
Bind<TranscriptPageMediaWidgetViewModelForWebPage>().ToSelf().InSingletonScope();
Bind<TranscriptPageTranscriptWidgetViewModelForWebPage>().ToSelf().InSingletonScope();
Bind<WebPageTranscriptProvider>().ToSelf().InSingletonScope();
Bind<ITranscriptProvider>().To<WebPageTranscriptProvider>().WhenInjectedInto<TranscriptPageTranscriptWidgetViewModelForWebPage>();
//Bind<ITranscriptProvider>().To<WebPageTranscriptProvider>();
Bind<ITranscriptRendererWidget>().To<TranscriptPageTranscriptWidgetViewModelForWebPage>();
Bind<IMediaRendererWidget>().To<TranscriptPageMediaWidgetViewModelForWebPage>();
}
}
次に、NinjectWebCommons.cs に次のものがあります。
private static IKernel CreateKernel()
{
var kernel = new StandardKernel(new WebPageModule(),new TweeterModule(), new BookmarkModule());
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
kernel.Settings.AllowNullInjection = true;//http://stackoverflow.com/questions/10517962/using-default-parameter-values-with-ninject-3-0
RegisterServices(kernel);
return kernel;
}
次に、プロパティ インジェクションを使用します: https://github.com/ninject/ninject/wiki/Injection-Patterns
私の「パブリッククラスTranscriptPageTranscriptWidgetViewModelForWebPage:ITranscriptRendererWidget」で
ここにあります:
[Inject]
public ITranscriptProvider TranscriptProvider
{
get { return _transcriptProvider; }
set { _transcriptProvider = value; }
}
しかし、コンストラクターに入って _transcriptProvider を使用しようとすると、NULL になります。
public TranscriptPageTranscriptWidgetViewModelForWebPage(string dataEndpoint, string focusCue)
{
InitParentInterfaceProperties();
Transcript = _transcriptProvider.GetTranscript(new Uri(dataEndpoint));
FocusCue = focusCue.Replace("*", "").ToLower();
}
私が間違っていることは何ですか?ありがとう!アル