WPF Ninject NullReferenceException в ViewModel

Реализую WPF MVVM приложение, использую библиотеку DevExpress. Нужно добавить Ninject, вот мои классы:

public interface IConvert
{
    void SaveFile(string text, string type);
}

 public class FileConvert : IConvert
 {
    ... 
 }

 

Мой App.xaml.cs:

public partial class App : Application
{
    private IKernel container;
    protected override void OnStartup(StartupEventArgs e)
    {
       // IocKernel.Initialize(new IocConfiguration());
        base.OnStartup(e);
        ConfigureContainer();
        ComposeObjects();
        Current.MainWindow.Show();
    }
    private void ConfigureContainer()
    {
        this.container = new StandardKernel();
        container.Bind<IConvert>().To<FileConvert>().InTransientScope();
    }

    private void ComposeObjects()
    {
        Current.MainWindow = this.container.Get<MainWindow>();
       
    }
}

Представление MovieListView:

  DataContext="{dxmvvm:ViewModelSource Type={x:Type ViewModels:MovieListViewModel}}"
           d:DesignHeight="400" d:DesignWidth="635">
<dxmvvm:Interaction.Behaviors>
    <dx:WindowedDocumentUIService>
        <dx:WindowedDocumentUIService.WindowStyle>
            <Style TargetType="dx:DXWindow">
                <Setter Property="Width" Value="300"/>
                <Setter Property="Height" Value="300"/>
            </Style>
        </dx:WindowedDocumentUIService.WindowStyle>
    </dx:WindowedDocumentUIService>
</dxmvvm:Interaction.Behaviors>

<Grid>
    ...
</Grid>

MainWindow.xaml:

<dx:ThemedWindow 
x:Class="DXAppWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:views="clr-namespace:DXAppWPF.Views"
Title="MainWindow" Height="400" Width="650" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
<Grid>
    <views:MovieListView>
    </views:MovieListView>
</Grid> </dx:ThemedWindow>

И мой класс модели представления:

[POCOViewModel]
public class MovieListViewModel
{
    public virtual MovieList Movies { get; set; }
    private IConvert _convert;

    [Inject]
    public MovieListViewModel(IConvert convert)  //Конструктор не вызывается
    {
        _convert = convert;
    }
    protected MovieListViewModel()
    {
        Movies = new MovieList();
    }
    public static MovieListViewModel Create()
    {
        return ViewModelSource.Create(() => new MovieListViewModel());
    }

    [ServiceProperty(SearchMode = ServiceSearchMode.PreferParents)]
    protected virtual IDocumentManagerService DocumentManagerService { get { return null; } }


    public void SaveCVS(object sender){

       _convert.SaveFile(CheckRow(sender), "csv");  //Ошибка здесь, _convert пустой
    }

    private string CheckRow(object sender)
    {
        ...
        return text;
    }
}

Как сделать, чтоб конструктор MovieListViewModel(IConvert convert) в модели представления вызывался?


Ответы (0 шт):