madsodgaard / vapor-auth-template

A Vapor 4 template with authentication, Fluent, JWT, Queues, repository pattern, testing and more.
MIT License
232 stars 35 forks source link

Repositories is reinstantiated every access? #18

Open JetForMe opened 2 years ago

JetForMe commented 2 years ago

There's a bit of code I don't understand, on https://github.com/madsodgaard/vapor-auth-template/blob/fc3f4a7d8a6c3f74305c38718f0798728d46fda1/Sources/App/Services/Repositories.swift#L60

    var repositories: Repositories {
        .init(app: self)
    }

This results in Repositories being instantiated on every access.

madsodgaard commented 2 years ago

@JetForMe It's only Application.Repositories that is instantiated, that type is just a helper type for accessing the actual factory methods for repositories. The actual factory methods/closures are stored in app.storage with the Application.Repositories.Storage type, so they are persistent across the entire Application

JetForMe commented 2 years ago

That's not what I see when I put a breakpoint there. It gets called multiple times.