vapor-auth-template icon indicating copy to clipboard operation
vapor-auth-template copied to clipboard

Repositories is reinstantiated every access?

Open JetForMe opened this issue 4 years ago • 2 comments

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.

JetForMe avatar Nov 24 '21 01:11 JetForMe

@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

madsodgaard avatar Nov 24 '21 08:11 madsodgaard

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

JetForMe avatar Nov 24 '21 19:11 JetForMe