private static IObservable <Unit> WhenOrganizationLookupView(this XafApplication application)
 => application.WhenDetailViewCreated().Where(t => t.e.View.Model == application.Model.TenantManager().StartupView)
 .SelectMany(t => t.e.View.GetItems <LookupPropertyEditor>().Where(editor => editor.MemberInfo.MemberType == application.Model.TenantManager().OrganizationType).ToObservable()
             .SelectMany(editor => editor.GetFieldValue("helper").WhenEvent(nameof(LookupEditorHelper.CustomCreateCollectionSource))
                         .Select(pattern => pattern.EventArgs).Cast <CustomCreateCollectionSourceEventArgs>()
                         .Do(e => {
     var collectionSourceBase = application.CreateCollectionSource(
         application.CreateNonSecuredObjectSpace(), editor.MemberInfo.MemberType,
         editor.View.Id);
     collectionSourceBase.Criteria[nameof(TenantManagerService)] = CriteriaOperator.Parse(application.Model.TenantManager().Registration);
     e.CollectionSource = collectionSourceBase;
 })))
 // => application.WhenFrameCreated().WhenFrame(Nesting.Nested).Where(frame => frame.Context==TemplateContext.LookupControl)
 //     .SelectMany(frame => application.WhenListViewCreating(application.Model.TenantManager().OrganizationType)
 //         .Do(t => {
 //             var modelListView = (IModelListView)application.Model.Views[t.e.ViewID];
 //             var nonSecuredObjectSpace = application.CreateNonSecuredObjectSpace();
 //             t.e.View = application.CreateListView(modelListView, application.CreateCollectionSource(nonSecuredObjectSpace,modelListView.ModelClass.TypeInfo.Type,modelListView.Id),true);
 //         })
 //         .To(frame))
 // .WhenFrame(frame => frame.Application.Model.TenantManager().OrganizationType)
 // .Cast<NestedFrame>()
 // .Where(frame => frame.Application.Model.TenantManager().StartupView==frame.ViewItem.View.Model)
 // .Do(frame => {
 //
 //     frame.GetController<NewObjectViewController>().NewObjectAction.Active[nameof(TenantManagerService)] = false;
 //     frame.View.AsListView().CollectionSource.Criteria[nameof(TenantManagerService)]= CriteriaOperator.Parse(frame.View.Model.Application.TenantManager().Registration)
 //         ;
 // })
 .FirstAsync()
 // .TraceTenantManager(t => t?.View?.Id)
 .ToUnit();
        public static IList <object> Organizations(this XafApplication application)
        {
            using var objectSpace = application.CreateNonSecuredObjectSpace();
            var model = application.Model.TenantManager();

            return(objectSpace.GetObjects(model.Organization.TypeInfo.Type, CriteriaOperator.Parse(model.Registration)).Cast <object>().ToArray());
        }