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

Remove the ability to use the regular Assembly type in Knit #177

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions Sources/Knit/Module/ModuleAssembler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class ModuleAssembler {
*/
public convenience init(
parent: ModuleAssembler? = nil,
_ modules: [any Assembly],
_ modules: [any ModuleAssembly],
overrideBehavior: OverrideBehavior = .defaultOverridesWhenTesting,
assemblyValidation: ((any ModuleAssembly.Type) throws -> Void)? = nil,
errorFormatter: ModuleAssemblerErrorFormatter = DefaultModuleAssemblerErrorFormatter(),
Expand Down Expand Up @@ -68,17 +68,14 @@ public final class ModuleAssembler {
// Internal required init that throws rather than fatal errors
required init(
parent: ModuleAssembler? = nil,
_modules modules: [any Assembly],
_modules modules: [any ModuleAssembly],
overrideBehavior: OverrideBehavior = .defaultOverridesWhenTesting,
assemblyValidation: ((any ModuleAssembly.Type) throws -> Void)? = nil,
errorFormatter: ModuleAssemblerErrorFormatter = DefaultModuleAssemblerErrorFormatter(),
postAssemble: ((Container) -> Void)? = nil
) throws {
let moduleAssemblies = modules.compactMap { $0 as? any ModuleAssembly }
let nonModuleAssemblies = modules.filter { !($0 is any ModuleAssembly) }

self.builder = try DependencyBuilder(
modules: moduleAssemblies,
modules: modules,
assemblyValidation: assemblyValidation,
overrideBehavior: overrideBehavior,
isRegisteredInParent: { type in
Expand All @@ -97,7 +94,6 @@ public final class ModuleAssembler {
self._container.register(DependencyTree.self) { _ in dependencyTree }

let assembler = Assembler(container: self._container)
assembler.apply(assemblies: nonModuleAssemblies)
assembler.apply(assemblies: builder.assemblies)
postAssemble?(_container)

Expand Down
9 changes: 3 additions & 6 deletions Sources/Knit/Module/ScopedModuleAssembler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public final class ScopedModuleAssembler<ScopedResolver> {

public convenience init(
parent: ModuleAssembler? = nil,
_ modules: [any Assembly],
_ modules: [any ModuleAssembly],
overrideBehavior: OverrideBehavior = .defaultOverridesWhenTesting,
errorFormatter: ModuleAssemblerErrorFormatter = DefaultModuleAssemblerErrorFormatter(),
postAssemble: ((Container) -> Void)? = nil,
Expand All @@ -48,17 +48,14 @@ public final class ScopedModuleAssembler<ScopedResolver> {
// Internal required init that throws rather than fatal errors
required init(
parent: ModuleAssembler? = nil,
_modules modules: [any Assembly],
_modules modules: [any ModuleAssembly],
overrideBehavior: OverrideBehavior = .defaultOverridesWhenTesting,
errorFormatter: ModuleAssemblerErrorFormatter = DefaultModuleAssemblerErrorFormatter(),
postAssemble: ((Container) -> Void)? = nil
) throws {
// For provided modules, fail early if they are scoped incorrectly
for assembly in modules {
guard let moduleAssembly = assembly as? any ModuleAssembly else {
continue
}
let moduleAssemblyType = type(of: moduleAssembly)
let moduleAssemblyType = type(of: assembly)
if moduleAssemblyType.resolverType != ScopedResolver.self {
let scopingError = ScopedModuleAssemblerError.incorrectTargetResolver(
expected: String(describing: ScopedResolver.self),
Expand Down