Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encapsulate project to injectable parts #28

Open
snys98 opened this issue Jun 4, 2018 · 10 comments
Open

encapsulate project to injectable parts #28

snys98 opened this issue Jun 4, 2018 · 10 comments
Assignees
Labels
enhancement New feature or request priority: high
Milestone

Comments

@snys98
Copy link

snys98 commented Jun 4, 2018

I'm wondering if it is possible to change the structure of this project to two different projects(or nuget packages would be better).

  • IdentityServer4.Admin
    this project will register all operations to a specific endpoint(like "/identity-server-admin") as a rest api.

  • IdentityServer4.Admin.UI
    this project will register all default page to a specific endpoint(like "/identity-server-admin-ui") and it would be possible to inject some css or js or something.

Just like what swagger&swagger-ui has done.

Besides, thanks for your huge efforts for this repo.

@snys98 snys98 changed the title encapsulate project to injectable part encapsulate project to injectable parts Jun 4, 2018
@skoruba
Copy link
Owner

skoruba commented Jun 4, 2018

Great idea @snys98.

I think it's absolutely possible. I want to prepare the REST api like you mentioned.

What do you suggest with UI part?

Thank you for your feedback. :)

@skoruba skoruba self-assigned this Jun 4, 2018
@skoruba skoruba added the enhancement New feature or request label Jun 4, 2018
@snys98
Copy link
Author

snys98 commented Jun 4, 2018

@skoruba
I used to modify something of injecting a UI.

Here register a middleware which serves the index.html and enable directory browse into the assembly(where we can put pages there):
https://github.com/microexs/Microex.Swagger/blob/8159f6ac84c9672ea938a0f1d760035436641e62/Microex.Swagger/SwaggerUI/SwaggerUIBuilderExtensions.cs#L19

And here to inject things we need to customize the pages.
https://github.com/microexs/Microex.Swagger/blob/8159f6ac84c9672ea938a0f1d760035436641e62/Microex.Swagger/SwaggerUI/index.html#L30
https://github.com/microexs/Microex.Swagger/blob/8159f6ac84c9672ea938a0f1d760035436641e62/Microex.Swagger/SwaggerUI/SwaggerUIIndexMiddleware.cs#L47
https://github.com/microexs/Microex.Swagger/blob/605c57d1843c53a55738ac499f4bc35bc3ea7a32/Microex.Swagger/SwaggerUI/SwaggerUIOptionsExtensions.cs#L14

But considering there are multiple pages and all these pages requires authentication of a role like "IdentityServerAdmin", it would be much more harder to achieve this.

Besides, IdentityServer has already provided some model like IdentityServer4.Model.Client. So, I'm wondering can these models be used as dtos?

@skoruba
Copy link
Owner

skoruba commented Jun 6, 2018

I am working on REST api, but I am wondering how distribute the set of controllers as nuget package - what do you think about it @snys98?

I think - it is possible to add into nuget package some repositories and services that are connected with database model but what about api endpoints? :)

@snys98
Copy link
Author

snys98 commented Jun 7, 2018

Maybe we should forget about the MVC pattern but try to implement a middleware instead.

I suggest all these could be done with a single line in the pipeline, like:

app.UseIdentityAdmin(options=>{
        option.EndPoint = "identity-admin";
        // more configs...
}

Then the api endpoint("/identity-admin") should deal with all the request that has the url prefix of "identity-admin" then map the sub-urls to corresponding handler functions.

@skoruba
Copy link
Owner

skoruba commented Jun 8, 2018

I've found the solution, that it's possible to add controllers from another assembly like this:

services.AddMvc()
                .AddApplicationPart(typeof(ClientController).Assembly)
                .AddControllersAsServices();

This post describes how to implement dynamic routing with another assembly.

I've built extension method like this:

public static IServiceCollection AddIdentityServerAdminApi(this IServiceCollection services, Action<ApiRouteConfiguration> configureRoute)
        {
            var options = new ApiRouteConfiguration();
            services.AddSingleton(options);
            configureRoute?.Invoke(options);

            var serviceProvider = services.BuildServiceProvider();
            var apiRouteConfiguration = serviceProvider.GetService<ApiRouteConfiguration>();

            services.AddMvc()
                .AddApplicationPart(typeof(ClientController).Assembly)
                .AddControllersAsServices()
                .AddApiRoutingConfiguration(apiRouteConfiguration); //based on the SO post

            return services;
        }

In Startup.cs:

services.AddIdentityServerAdminApi(configuration =>
            {
                configuration.ApiPrefix = "admin-ui/api/";
            });

What do you think about it?

I've wondered about custom middleware and I think this approach above it's better because in custom middleware you are working with "raw" http request and you need implement everything from scratch. :)

@snys98
Copy link
Author

snys98 commented Jun 12, 2018

@skoruba
That's great. It's actually the way of Microsoft.AspNetCore.Identity.UI.

I know little about this kind of implemention. But I guess this may help.

@skoruba
Copy link
Owner

skoruba commented Jun 15, 2018

@snys98 Great point. I am working on it but I can't find any solution how to share the resources for localization. Razor class library provides great posibilities how to share UI across among multiple projects, but all available samples are without localization. Any idea? :)

@skoruba
Copy link
Owner

skoruba commented Jun 19, 2018

Similiar use case with sharing resx files from class library - aspnet/Localization#328

  • Or use Resources (*.resx) as a part of nuget package that will be unpack in the solution - something like this:

.nuspec:

<?xml version="1.0"?>
<package>
    <metadata>...
    </metadata>
    <files>
        <!-- Add all resource files -->
        <file src="Resources\**\*.resx" target="content\Resources" />
    </files>
</package>

@skoruba skoruba added this to the 1.0.0-beta-1 milestone Jun 19, 2018
@snys98
Copy link
Author

snys98 commented Jun 21, 2018

@skoruba
Sorry, I had a busy time in the last few days. Sounds like you've solved it. Congratulations.

@skoruba
Copy link
Owner

skoruba commented Jun 23, 2018

@snys98 Yes, it seems the combination of Razor Class Library and Resources for localization working well.

I am currently working on splitting the solution into three parts:

  • UI
  • EntityFramework
  • Services (or Business Logic)

After that I'll create some nuget packages.

Again - thank you for your good ideas. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority: high
Projects
None yet
Development

No branches or pull requests

2 participants