Skip to main content
All docs
V26.1
  • IocServiceProvider.Default Property

    Gets or sets the global default IocServiceProvider instance used by the DevExpress MVVM framework to resolve view models through the dependency injection container.

    Namespace: DevExpress.Mvvm

    Assembly: DevExpress.Mvvm.v26.1.dll

    Declaration

    public static IocServiceProvider Default { get; set; }

    Property Value

    Type Description
    IocServiceProvider

    The global IocServiceProvider instance.

    Remarks

    The following code snippet configures the global provider before WPF starts loading StartupUri/XAML:

    using DevExpress.Mvvm;
    using Microsoft.Extensions.DependencyInjection;
    using MvvmApp.ViewModels;
    
    namespace MvvmApp {
        public partial class App : Application {
            // ...
            protected override void OnStartup(StartupEventArgs e) {
                IServiceProvider services = new ServiceCollection()
                    .AddTransient<MainViewModel>()
                    .BuildServiceProvider();
                // Configure the global provider before WPF starts loading StartupUri/XAML
                // The {dxmvvm:Ioc ...} config can resolve types during initialization in XAML
                IocServiceProvider.Default.ConfigureServices(services);
                base.OnStartup(e);
    
                var mainWindow = new MainWindow();
                MainWindow = mainWindow;
                mainWindow.Show();
            }
        }
    }
    

    Refer to the IocExtension for additional information.

    See Also