private async Task<IdentityAdminMetadata> GetMetadataAsync()
        {
            if (_metadata == null)
            {
                _metadata = await this._identityAdminService.GetMetadataAsync();
                if (_metadata == null) throw new InvalidOperationException("GetMetadataAsync returned null");
                _metadata.Validate();
            }

            return _metadata;
        }
        public ClientDetailResource(ClientDetail client, UrlHelper url, IdentityAdminMetadata idmAdminMeta)
        {
            if (client == null) throw new ArgumentNullException("client");
            if (url == null) throw new ArgumentNullException("url");
            if (idmAdminMeta == null) throw new ArgumentNullException("idmAdminMeta");

            Data = new ClientDetailDataResource(client, url, idmAdminMeta);

            var links = new Dictionary<string, string>();
            if (idmAdminMeta.ClientMetaData.SupportsDelete)
            {
                links["Delete"] = url.Link(Constants.RouteNames.DeleteClient, new {subject = client.Subject});
            }
            Links = links;
        }
        public ScopeDetailResource(ScopeDetail scope, UrlHelper url, IdentityAdminMetadata idmAdminMeta)
        {
            if (scope == null) throw new ArgumentNullException("scope");
            if (url == null) throw new ArgumentNullException("url");
            if (idmAdminMeta == null) throw new ArgumentNullException("idmAdminMeta");

            Data = new ScopeDetailDataResource(scope, url, idmAdminMeta);

            var links = new Dictionary<string, string>();
            if (idmAdminMeta.ClientMetaData.SupportsDelete)
            {
                links["Delete"] = url.Link(Constants.RouteNames.DeleteScope, new { subject = scope.Subject });
            }
            Links = links;
        }
        public Task<IdentityAdminMetadata> GetMetadataAsync()
        {
            var updateClient = new List<PropertyMetadata>();
            updateClient.AddRange(PropertyMetadata.FromType<Data.StoredClient>());

            var createClient = new List<PropertyMetadata>
            {
                PropertyMetadata.FromProperty<Data.StoredClient>(x => x.ClientName,"ClientName", required: true),
                PropertyMetadata.FromProperty<Data.StoredClient>(x => x.ClientId,"ClientId", required: true),
            };

            var client = new ClientMetaData
            {
                SupportsCreate = true,
                SupportsDelete = true,
                CreateProperties = createClient,
                UpdateProperties = updateClient
            };


            var updateScope = new List<PropertyMetadata>();
            updateScope.AddRange(PropertyMetadata.FromType<Data.StoredScope>());

            var createScope = new List<PropertyMetadata>
            {
                PropertyMetadata.FromProperty<Data.StoredScope>(x => x.Name,"ScopeName", required: true),
            };

            var scope = new ScopeMetaData
            {
                SupportsCreate = true,
                SupportsDelete = true,
                CreateProperties = createScope,
                UpdateProperties = updateScope
            };


            var identityAdminMetadata = new IdentityAdminMetadata
            {
                ClientMetaData = client,
                ScopeMetaData = scope
            };

            return Task.FromResult(identityAdminMetadata);
        }
        private IdentityAdminMetadata GetMetadata()
        {
            if (_metadata == null)
            {
                var updateClient = new List<PropertyMetadata>();
                updateClient.AddRange(PropertyMetadata.FromType<InMemoryClient>());

                var createClient = new List<PropertyMetadata>
                {
                    PropertyMetadata.FromProperty<InMemoryClient>(x => x.ClientName, "ClientName", required: true),
                    PropertyMetadata.FromProperty<InMemoryClient>(x => x.ClientId, "ClientId", required: true),
                };

                var client = new ClientMetaData
                {
                    SupportsCreate = true,
                    SupportsDelete = true,
                    CreateProperties = createClient,
                    UpdateProperties = updateClient
                };


                var updateScope = new List<PropertyMetadata>();
                updateScope.AddRange(PropertyMetadata.FromType<InMemoryScope>());

                var createScope = new List<PropertyMetadata>
                {
                    PropertyMetadata.FromProperty<InMemoryScope>(x => x.Name, "ScopeName", required: true),
                };

                var scope = new ScopeMetaData
                {
                    SupportsCreate = true,
                    SupportsDelete = true,
                    CreateProperties = createScope,
                    UpdateProperties = updateScope
                };


                _metadata = new IdentityAdminMetadata
                {
                    ClientMetaData = client,
                    ScopeMetaData = scope
                };
            }
            return _metadata;
        }