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

use_service documentation seems wrong #121

Open
pkese opened this issue Apr 2, 2024 · 2 comments
Open

use_service documentation seems wrong #121

pkese opened this issue Apr 2, 2024 · 2 comments

Comments

@pkese
Copy link

pkese commented Apr 2, 2024

I've been trying to figure out https://www.falcoframework.com/docs/host.html#add_service

There's function dbConnectionService that creates a service:

    // Register our database connection factory service
    let dbConnectionService (svc : IServiceCollection) =
        svc.AddSingleton<IDbConnectionFactory, DbConnectionFactory>(fun _ ->
            // Load default connection string from appsettings.json
            let connectionString = config.GetConnectionString("Default")
            new DbConnectionFactory(connectionString))

    webHost [||] {
        endpoints [
            get "/" (Response.ofPlainText "Hello world")
        ]
    }

... but that function just sits there and doesn't seem to be called from anywhere.

Is that correct? I was supposing that someone should somewhere call use_service.

Also:
The chapter starts with: Note the use of the ConfigurationBuilder, but I can't find a ConfigurationBuilder anywhere in the example. Maybe that needs more explanation, if the ConfigurationBuilder is used in some implicit manner (this is all very hard to understand for newbies).

And:
ConfigurationBuiler is misspelled on the page (without 'd').

@pkese
Copy link
Author

pkese commented Apr 2, 2024

Another thing I'm trying to figure out:

I wish to include 'BananaCakePop' app that comes in a separate nuget package and one needs to include it into the server and bind it to a route:

app.UseEndpoints(endpoints =>
{
    endpoints.MapGraphQL();
    endpoints.MapBananaCakePop("/my-graphql-ui");
});

(example taken from https://chillicream.com/docs/bananacakepop/v2/integrations/hot-chocolate)

In order to do so, I assume I'd need access to the IAppliationBuilder, but that is embedded in the HostBuilder computaion expression and not exposed to the outside world.

Nor can I figure out how I'd include this in the endpoints [ ... ] section.

@nicholas-peterson
Copy link

nicholas-peterson commented May 7, 2024

Maybe not understanding your questions, but is the end of your [<EntryPoint>] function something like this:

[<EntryPoint>]
let main args =
    webHost [||] {
        use_service yourMiddleWareFuncHere
        endpoints (generateEndpoints ())
    }

    0

You can use the helper functions like use_service inside that webHost record.

Then the trick would be making the signatures match. So access to the IApplicationBuilder would be available using use_middleware with a function that has a signature of IApplicationBuilder -> IApplicationBuilder.

Does that help or am I missing your point entirely (very possible :) )?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants