B1.01 Security: Authorization (C# classes) (Wpf) - chempkovsky/CS2WPF-and-CS2XAMARIN GitHub Wiki

Note 1:

In "A7 Security: Authorization (ViewModels)"-article It was described of how to import ViewModel definition. Not only the ViewModels definitions were imported, but also the Web Api service definitions, UI List Properties and UI Form Properties. Thus, there is no need to make any customizations before generating the code. The only thing to do is make sure that there were no errors during the import operation.

Instructions:

  • Run Viisual Studion 2019
  • Open the “WpfDemo” solution, which is located in the folder:
    • C:\Development\WpfDemo

Step #1 Interfaces:

  • Right click root-node of ModelInterfacesClassLibrary-project
    • Open Wpf Forms Wizard

DB structure

  • click next button on the first page

DB structure

  • On the second page
    • select aspnetchckdbcontext - DBcontext
    • click Next-button

DB structure

  • On the third page
    • select any item except ==Context==. For instance, select aspnetdashboardView.
    • click Next-button

DB structure

  • On the fourth page
    • click 'Batch processing'-button
    • Batch Actions dialog will shown

DB structure

  • In 'Batch Actions' dialog
    • select 14210-AspNetAllInterfacesBatch.json
    • click 'Start'-button

DB structure

Close 'Batch Actions' dialog and close Wpf Forms Wizard. Here is a result:

DB structure

Step #2 Classes:

  • Right click root-node of ModelServicesPrismModule-project
    • Open Wpf Forms Wizard

DB structure

  • click next button on the first page

DB structure

  • On the second page
    • select aspnetchckdbcontext - DBcontext
    • click Next-button

DB structure

  • On the third page
    • select any item except ==Context==. For instance, select aspnetdashboardView.
    • click Next-button

DB structure

  • On the fourth page
    • click 'Batch processing'-button
    • Batch Actions dialog will shown

DB structure

  • In 'Batch Actions' dialog
    • select 14220-AspNetAllModelsBatch.json
    • click 'Start'-button

DB structure

  • In 'Batch Actions' dialog
    • select 14230-AspNetAllServicesBatch.json
    • click 'Start'-button

DB structure

  • In 'Batch Actions' dialog
    • select 14240-AspNetAllSformsBatch.json
    • click 'Start'-button

DB structure

  • In 'Batch Actions' dialog
    • select 14250-AspNetAllEformsBatch.json
    • click 'Start'-button

DB structure

  • In 'Batch Actions' dialog
    • select 14260-AspNetAllLformsBatch.json
    • click 'Start'-button

DB structure

  • In 'Batch Actions' dialog
    • select 14270-AspNetAllO2mMaskBatch.json
    • click 'Start'-button

DB structure

Close 'Batch Actions' dialog and close Wpf Forms Wizard. Here is a result:

DB structure

Step #3 dependency injection:

dependency injection of Services:

Open each file for all nested folders under "services/asp"-folder of ModelServicesPrismModule-project and follow the instructions at the beginning of the file:

DB structure

As a result, in the "ModelServicesPrismModuleModule.cs"-file the following lines of code will be added to the body of "RegisterTypes(IContainerRegistry containerRegistry)"-method:

        public void RegisterTypes(IContainerRegistry containerRegistry)
        {
            ...
            // asp
            containerRegistry.Register<IAspnetdashboardViewService, AspnetdashboardViewService>();
            containerRegistry.Register<IAspnetdashboardViewServiceCopyPermission, AspnetdashboardViewServiceCopyPermission>();
            containerRegistry.Register<IAspnetmodelViewService, AspnetmodelViewService>();
            containerRegistry.Register<IAspnetmodelViewServiceCopyPermission, AspnetmodelViewServiceCopyPermission>();
            containerRegistry.Register<IAspnetrolemaskViewService, AspnetrolemaskViewService>();
            containerRegistry.Register<IAspnetroleViewService, AspnetroleViewService>();
            containerRegistry.Register<IAspnetusermaskViewService, AspnetusermaskViewService>();
            containerRegistry.Register<IAspnetusermaskViewServicePermission, AspnetusermaskViewServicePermission>();
            containerRegistry.Register<IAspnetuserrolesViewService, AspnetuserrolesViewService>();
            containerRegistry.Register<IAspnetuserViewService, AspnetuserViewService>();

        }

dependency injection of ViewModels:

Open each file for all nested folders under "services/asp"-folder of ModelServicesPrismModule-project and follow the instructions at the beginning of the file:

DB structure

As a result, in the "ModelServicesPrismModuleModule.cs"-file the following lines of code will be added to the body of "RegisterTypes(IContainerRegistry containerRegistry)"-method:

        public void RegisterTypes(IContainerRegistry containerRegistry)
        {
            ...
            // asp ViewModels
            // According to requirements of the "AspnetdashboardViewDshCheckedModelViewModel.cs"-file of "AspnetdashboardViewDshCheckedModelViewModel"-project. 
            ViewModelLocationProvider.Register<AspnetdashboardViewDshCheckedModelUserControl, AspnetdashboardViewDshCheckedModelViewModel>();
            // According to requirements of the "AspnetdashboardViewDshCheckedModelViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetdashboardViewDshCheckedModelUserControl>("AspnetdashboardViewDshCheckedModelUserControl");
            // According to requirements of the "AspnetdashboardViewLdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetdashboardViewLdlgUserControl, AspnetdashboardViewLdlgViewModel>("AspnetdashboardViewLdlgViewModel");
            // According to requirements of the "AspnetdashboardViewLformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetdashboardViewLformUserControl, AspnetdashboardViewLformViewModel>();
            // According to requirements of the "AspnetdashboardViewLformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetdashboardViewLformUserControl>("AspnetdashboardViewLformUserControl");
            // According to requirements of the "AspnetdashboardViewSdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetdashboardViewSdlgUserControl, AspnetdashboardViewSdlgViewModel>("AspnetdashboardViewSdlgViewModel");
            // According to requirements of the "AspnetdashboardViewSformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetdashboardViewSformUserControl, AspnetdashboardViewSformViewModel>();
            // According to requirements of the "AspnetdashboardViewSformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetdashboardViewSformUserControl>("AspnetdashboardViewSformUserControl");
            // According to requirements of the "AspnetdashboardViewEdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetdashboardViewEdlgUserControl, AspnetdashboardViewEdlgViewModel>("AspnetdashboardViewEdlgViewModel");
            // According to requirements of the "AspnetdashboardViewEformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetdashboardViewEformUserControl, AspnetdashboardViewEformViewModel>();
            // According to requirements of the "AspnetdashboardViewEformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetdashboardViewEformUserControl>("AspnetdashboardViewEformUserControl");

            // According to requirements of the "AspnetmodelViewCheckedModelViewModel.cs"-file of "AspnetmodelViewCheckedModelViewModel"-project. 
            ViewModelLocationProvider.Register<AspnetmodelViewCheckedModelUserControl, AspnetmodelViewCheckedModelViewModel>();
            // According to requirements of the "AspnetmodelViewCheckedModelViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetmodelViewCheckedModelUserControl>("AspnetmodelViewCheckedModelUserControl");
            // According to requirements of the "AspnetmodelViewLdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetmodelViewLdlgUserControl, AspnetmodelViewLdlgViewModel>("AspnetmodelViewLdlgViewModel");
            // According to requirements of the "AspnetmodelViewLformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetmodelViewLformUserControl, AspnetmodelViewLformViewModel>();
            // According to requirements of the "AspnetmodelViewLformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetmodelViewLformUserControl>("AspnetmodelViewLformUserControl");
            // According to requirements of the "AspnetmodelViewSdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetmodelViewSdlgUserControl, AspnetmodelViewSdlgViewModel>("AspnetmodelViewSdlgViewModel");
            // According to requirements of the "AspnetmodelViewSformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetmodelViewSformUserControl, AspnetmodelViewSformViewModel>();
            // According to requirements of the "AspnetmodelViewSformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetmodelViewSformUserControl>("AspnetmodelViewSformUserControl");
            // According to requirements of the "AspnetmodelViewEformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetmodelViewEformUserControl, AspnetmodelViewEformViewModel>();
            // According to requirements of the "AspnetmodelViewEformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetmodelViewEformUserControl>("AspnetmodelViewEformUserControl");
            // According to requirements of the "AspnetmodelViewEdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetmodelViewEdlgUserControl, AspnetmodelViewEdlgViewModel>("AspnetmodelViewEdlgViewModel");


            // According to requirements of the "AspnetrolemaskViewLdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetrolemaskViewLdlgUserControl, AspnetrolemaskViewLdlgViewModel>("AspnetrolemaskViewLdlgViewModel");
            // According to requirements of the "AspnetrolemaskViewLformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetrolemaskViewLformUserControl, AspnetrolemaskViewLformViewModel>();
            // According to requirements of the "AspnetrolemaskViewLformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetrolemaskViewLformUserControl>("AspnetrolemaskViewLformUserControl");
            // According to requirements of the "AspnetrolemaskViewSdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetrolemaskViewSdlgUserControl, AspnetrolemaskViewSdlgViewModel>("AspnetrolemaskViewSdlgViewModel");
            // According to requirements of the "AspnetrolemaskViewSformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetrolemaskViewSformUserControl, AspnetrolemaskViewSformViewModel>();
            // According to requirements of the "AspnetrolemaskViewSformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetrolemaskViewSformUserControl>("AspnetrolemaskViewSformUserControl");
            // According to requirements of the "AspnetrolemaskViewEformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetrolemaskViewEformUserControl, AspnetrolemaskViewEformViewModel>();
            // According to requirements of the "AspnetrolemaskViewEformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetrolemaskViewEformUserControl>("AspnetrolemaskViewEformUserControl");
            // According to requirements of the "AspnetrolemaskViewEdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetrolemaskViewEdlgUserControl, AspnetrolemaskViewEdlgViewModel>("AspnetrolemaskViewEdlgViewModel");

            // According to requirements of the "AspnetroleViewLdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetroleViewLdlgUserControl, AspnetroleViewLdlgViewModel>("AspnetroleViewLdlgViewModel");
            // According to requirements of the "AspnetroleViewLformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetroleViewLformUserControl, AspnetroleViewLformViewModel>();
            // According to requirements of the "AspnetroleViewLformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetroleViewLformUserControl>("AspnetroleViewLformUserControl");
            // According to requirements of the "AspnetroleViewO2mMaskViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetroleViewO2mMaskUserControl, AspnetroleViewO2mMaskViewModel>();
            // According to requirements of the "AspnetroleViewO2mMaskViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetroleViewO2mMaskUserControl>("AspnetroleViewO2mMaskUserControl");
            // According to requirements of the "AspnetroleViewSdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetroleViewSdlgUserControl, AspnetroleViewSdlgViewModel>("AspnetroleViewSdlgViewModel");
            // According to requirements of the "AspnetroleViewSformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetroleViewSformUserControl, AspnetroleViewSformViewModel>();
            // According to requirements of the "AspnetroleViewSformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetroleViewSformUserControl>("AspnetroleViewSformUserControl");
            // According to requirements of the "AspnetroleViewEformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetroleViewEformUserControl, AspnetroleViewEformViewModel>();
            // According to requirements of the "AspnetroleViewEformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetroleViewEformUserControl>("AspnetroleViewEformUserControl");
            // According to requirements of the "AspnetroleViewEdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetroleViewEdlgUserControl, AspnetroleViewEdlgViewModel>("AspnetroleViewEdlgViewModel");


            // According to requirements of the "AspnetusermaskViewEformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetusermaskViewEformUserControl, AspnetusermaskViewEformViewModel>();
            // According to requirements of the "AspnetusermaskViewEformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetusermaskViewEformUserControl>("AspnetusermaskViewEformUserControl");
            // According to requirements of the "AspnetusermaskViewEdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetusermaskViewEdlgUserControl, AspnetusermaskViewEdlgViewModel>("AspnetusermaskViewEdlgViewModel");


            // According to requirements of the "AspnetuserrolesViewLdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetuserrolesViewLdlgUserControl, AspnetuserrolesViewLdlgViewModel>("AspnetuserrolesViewLdlgViewModel");
            // According to requirements of the "AspnetuserrolesViewLformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetuserrolesViewLformUserControl, AspnetuserrolesViewLformViewModel>();
            // According to requirements of the "AspnetuserrolesViewLformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetuserrolesViewLformUserControl>("AspnetuserrolesViewLformUserControl");
            // According to requirements of the "AspnetuserrolesViewSdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetuserrolesViewSdlgUserControl, AspnetuserrolesViewSdlgViewModel>("AspnetuserrolesViewSdlgViewModel");
            // According to requirements of the "AspnetuserrolesViewSformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetuserrolesViewSformUserControl, AspnetuserrolesViewSformViewModel>();
            // According to requirements of the "AspnetuserrolesViewSformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetuserrolesViewSformUserControl>("AspnetuserrolesViewSformUserControl");
            // According to requirements of the "AspnetuserViewSdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetuserViewSdlgUserControl, AspnetuserViewSdlgViewModel>("AspnetuserViewSdlgViewModel");
            // According to requirements of the "AspnetuserrolesViewEdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetuserrolesViewEdlgUserControl, AspnetuserrolesViewEdlgViewModel>("AspnetuserrolesViewEdlgViewModel");

            // According to requirements of the "AspnetuserViewLdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetuserViewLdlgUserControl, AspnetuserViewLdlgViewModel>("AspnetuserViewLdlgViewModel");
            // According to requirements of the "AspnetuserViewLformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetuserViewLformUserControl, AspnetuserViewLformViewModel>();
            // According to requirements of the "AspnetuserViewLformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetuserViewLformUserControl>("AspnetuserViewLformUserControl");
            // According to requirements of the "AspnetuserViewO2mMaskViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetuserViewO2mMaskUserControl, AspnetuserViewO2mMaskViewModel>();
            // According to requirements of the "AspnetuserViewO2mMaskViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetuserViewO2mMaskUserControl>("AspnetuserViewO2mMaskUserControl");
            // According to requirements of the "AspnetuserViewSdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetuserViewSdlgUserControl, AspnetuserViewSdlgViewModel>("AspnetuserViewSdlgViewModel");
            // According to requirements of the "AspnetuserViewSformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetuserViewSformUserControl, AspnetuserViewSformViewModel>();
            // According to requirements of the "AspnetuserViewSformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetuserViewSformUserControl>("AspnetuserViewSformUserControl");
            // According to requirements of the "AspnetuserViewEformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetuserViewEformUserControl, AspnetuserViewEformViewModel>();
            // According to requirements of the "AspnetuserViewEformViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetuserViewEformUserControl>("AspnetuserViewEformUserControl");
            // According to requirements of the "AspnetuserViewEdlgViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterDialog<AspnetuserViewEdlgUserControl, AspnetuserViewEdlgViewModel>("AspnetuserViewEdlgViewModel");
            // According to requirements of the "AspnetuserViewO2mViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            ViewModelLocationProvider.Register<AspnetuserViewO2mUserControl, AspnetuserViewO2mViewModel>();
            // According to requirements of the "AspnetuserViewO2mViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.Register<UserControl, AspnetuserViewO2mUserControl>("AspnetuserViewO2mUserControl");
            // According to requirements of the "AspnetuserViewO2mViewModel.cs"-file of "ModelServicesPrismModule"-project. 
            containerRegistry.RegisterForNavigation<AspnetuserViewO2mUserControl, AspnetuserViewO2mViewModel>("AspnetuserViewO2mUserControl");

        }