<commit_before>//
//  ZContainer.swift
//  ZContainer
//
//  Created by <NAME> on 17.09.15.
//  Copyright © 2015 Zalando SE. All rights reserved.
//

import Foundation

/// Service Registry
public protocol ZRegistry {
    func register<Service>(factory: () -> Service)
}

/// Service Locator
public class ZContainer {
    // MARK: - Shared Instance
    private static let sharedRegistry = ServiceRegistry()
    
    /// Returns the default service locator.
    public static func defaultContainer() -> ZContainer {
        return sharedRegistry
    }
    
    /// Returns the default service registy.
    public static func defaultRegistry() -> ZRegistry {
        return sharedRegistry
    }
    
    // MARK: - Private Properties
    private var registry = [ObjectIdentifier: Any]()
    private let check: Bool
    
    init(check: Bool = true) {
        self.check = check
    }
    
    /// Returns a service matching the requested type.
    public func resolve<Service>(file: StaticString = __FILE__, line: UInt = __LINE__, function: StaticString = __FUNCTION__) -> Service! {
        if check {
            assert(function.stringValue.hasPrefix("init"), "resolve() should be called in init", file: file, line: line)
        }
        let serviceIdentifier = ObjectIdentifier(Service.self)
        guard let factory = registry[serviceIdentifier] as? () -> Service else {
            if check {
                fatalError("No registered factory for \(Service.self)", file: file, line: line)
            }
            return Service!()
        }
        return factory()
    }
}

private class ServiceRegistry: ZContainer, ZRegistry {
    func register<Service>(factory: () -> Service) {
        let serviceIdentifier = ObjectIdentifier(Service.self)
        registry[serviceIdentifier] = factory
    }
}<commit_msg>Always run your unit tests on a build server…<commit_after>//
//  ZContainer.swift
//  ZContainer
//
//  Created by <NAME> on 17.09.15.
//  Copyright © 2015 Zalando SE. All rights reserved.
//

import Foundation

/// Service Registry
public protocol ZRegistry {
    func register<Service>(factory: () -> Service)
}

/// Service Locator
public class ZContainer {
    // MARK: - Shared Instance
    private static let sharedRegistry = ServiceRegistry()
    
    /// Returns the default service locator.
    public static func defaultContainer() -> ZContainer {
        return sharedRegistry
    }
    
    /// Returns the default service registy.
    public static func defaultRegistry() -> ZRegistry {
        return sharedRegistry
    }
    
    // MARK: - Private Properties
    private var registry = [ObjectIdentifier: Any]()
    private let check: Bool
    
    init(check: Bool = true) {
        self.check = check
    }
    
    /// Returns a service matching the requested type.
    public func resolve<Service>(file: StaticString = __FILE__, line: UInt = __LINE__, function: StaticString = __FUNCTION__) -> Service! {
        if check {
            assert(function.stringValue.hasPrefix("init"), "resolve() should be called in init", file: file, line: line)
        }
        let serviceIdentifier = ObjectIdentifier(Service.self)
        guard let factory = registry[serviceIdentifier] as? () -> Service else {
            if check {
                fatalError("No registered factory for \(Service.self)", file: file, line: line)
            }
            return Service!()
        }
        return factory()
    }
}

class ServiceRegistry: ZContainer, ZRegistry {
    func register<Service>(factory: () -> Service) {
        let serviceIdentifier = ObjectIdentifier(Service.self)
        registry[serviceIdentifier] = factory
    }
}
{'fraction_non_alphanumeric': 0.10185690879300928, 'fraction_numerical': 0.005461496450027308, 'mean_word_length': 2.46875, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5380211', 'n_tokens_mistral': 958, 'n_tokens_neox': 919, 'n_words': 307}