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

Replace RequestContext initialization parameters with associatedtype #469

Merged
merged 4 commits into from
Jun 15, 2024

Conversation

adam-fowler
Copy link
Member

@adam-fowler adam-fowler commented Jun 10, 2024

Instead of

struct MyRequestContext: RequestContext {
    var coreContext: CoreRequestContext
    init(channel: Channel, logger: Logger) {
        self.coreContext = .init(allocator: channel.allocator, logger: logger)
    }
}

You have where, Source is the source of the request

struct MyRequestContext: RequestContext {
    var coreContext: CoreRequestContext
    init(source: Source) {
        self.coreContext = .init(source: Source)
    }
}

In the server situation Source is a struct that includes the logger and the channel. You can still access the channel via source.channel. In the lambda situation this would include the Event that triggered the lambda and the LambdaContext.

It makes context creation simpler and hides implementation details

@adam-fowler adam-fowler requested a review from Joannis June 10, 2024 10:28
Copy link
Member

@Joannis Joannis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this a lot. My only "concern" is that we lose the ability to add more properties to CoreRequestContext later with this setup. With the old setup, we could've added secondary inits to CoreRequestContext. Not sure if that's a fair concern though

@adam-fowler
Copy link
Member Author

adam-fowler commented Jun 10, 2024

I like this a lot. My only "concern" is that we lose the ability to add more properties to CoreRequestContext later with this setup. With the old setup, we could've added secondary inits to CoreRequestContext. Not sure if that's a fair concern though

Not sure how this affects your ability to write a secondary init for CoreRequestContext. You can still do that and call it from your custom context.

EDIT: @Joannis I think I get what you're at. If we require additional parameters from Channel we would have to extend the requirements for RequestContextSource. Yeah I don't think that this is an issue. If we needed other values from the Channel in the Hummingbird Library we would have found them now

* Merge BaseRequestContext and RequestContext into one protocol

* swiftformat

* Add InstantiableRequestContext
@adam-fowler adam-fowler merged commit d0b61e0 into main Jun 15, 2024
4 of 5 checks passed
@adam-fowler adam-fowler deleted the context-source branch June 15, 2024 09:45
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

Successfully merging this pull request may close these issues.

2 participants