<commit_before>#include <stdexcept>

#include "ComponentRegistration.h"
#include "ComponentRegistry.h"
#include "ContainerActivator.h"
#include "CurrentLifetimeScope.h"
#include "DelegateActivator.h"
#include "IComponentRegistry.h"
#include "ILifetimeScope.h"
#include "LifetimeScope.h"
#include "ProvidedInstanceActivator.h"
#include "TypedService.h"
#include "Container.h"


namespace Hypodermic
{

    std::shared_ptr< IComponentRegistry > Container::componentRegistry()
    {
        return componentRegistry_;
    }

    std::shared_ptr< void > Container::resolveComponent(std::shared_ptr< IComponentRegistration > registration)
    {
        return rootLifetimeScope_->resolveComponent(registration);
    }

    std::shared_ptr< void > Container::getOrCreateInstance(std::shared_ptr< IComponentRegistration > registration)
    {
        return registration->activator()->activateInstance(shared_from_this());
    }

    void Container::initialize()
    {
        std::vector< std::shared_ptr< Service > > services;
        services.push_back(std::make_shared< TypedService >(typeid(ILifetimeScope)));
        services.push_back(std::make_shared< TypedService >(typeid(IComponentContext)));

        componentRegistry_ = std::make_shared< ComponentRegistry >();

        componentRegistry_->addRegistration(std::make_shared< ComponentRegistration >(
            LifetimeScope::selfRegistrationId,
            std::make_shared< DelegateActivator< LifetimeScope > >(
                typeid(LifetimeScope),
                [](IComponentContext&) -> LifetimeScope*
                {
                    throw std::logic_error("Self registration cannot be activated");
                }),
            std::make_shared< CurrentLifetimeScope >(),
            InstanceSharing::Shared,
            InstanceOwnership::ExternallyOwned,
            services,
            std::unordered_map< std::type_index, std::shared_ptr< ITypeCaster > >()));

        services.clear();
        services.push_back(std::make_shared< TypedService >(typeid(IContainer)));

        componentRegistry_->addRegistration(std::make_shared< ComponentRegistration >(
            LifetimeScope::selfRegistrationId,
            std::make_shared< ContainerActivator >(shared_from_this()),
            std::make_shared< CurrentLifetimeScope >(),
            InstanceSharing::None, // this instance will actually be shared, but this prevents shared pointer circular references
            InstanceOwnership::ExternallyOwned,
            services,
            std::unordered_map< std::type_index, std::shared_ptr< ITypeCaster > >()));

        rootLifetimeScope_ = std::make_shared< LifetimeScope >(componentRegistry_);
        rootLifetimeScope_->initialize();
    }

} // namespace Hypodermic<commit_msg>Boost.Assign is prettier than push_backs<commit_after>#include <stdexcept>

#include <boost/assign.hpp>

#include "ComponentRegistration.h"
#include "ComponentRegistry.h"
#include "ContainerActivator.h"
#include "CurrentLifetimeScope.h"
#include "DelegateActivator.h"
#include "IComponentRegistry.h"
#include "ILifetimeScope.h"
#include "LifetimeScope.h"
#include "ProvidedInstanceActivator.h"
#include "TypedService.h"
#include "Container.h"


namespace Hypodermic
{

    std::shared_ptr< IComponentRegistry > Container::componentRegistry()
    {
        return componentRegistry_;
    }

    std::shared_ptr< void > Container::resolveComponent(std::shared_ptr< IComponentRegistration > registration)
    {
        return rootLifetimeScope_->resolveComponent(registration);
    }

    std::shared_ptr< void > Container::getOrCreateInstance(std::shared_ptr< IComponentRegistration > registration)
    {
        return registration->activator()->activateInstance(shared_from_this());
    }

    void Container::initialize()
    {
        using namespace boost::assign;

        std::vector< std::shared_ptr< Service > > services;
        services += std::make_shared< TypedService >(typeid(ILifetimeScope))
                  , std::make_shared< TypedService >(typeid(IComponentContext));

        componentRegistry_ = std::make_shared< ComponentRegistry >();

        componentRegistry_->addRegistration(std::make_shared< ComponentRegistration >(
            LifetimeScope::selfRegistrationId,
            std::make_shared< DelegateActivator< LifetimeScope > >(
                typeid(LifetimeScope),
                [](IComponentContext&) -> LifetimeScope*
                {
                    throw std::logic_error("Self registration cannot be activated");
                }),
            std::make_shared< CurrentLifetimeScope >(),
            InstanceSharing::Shared,
            InstanceOwnership::ExternallyOwned,
            services,
            std::unordered_map< std::type_index, std::shared_ptr< ITypeCaster > >()));

        services.clear();
        services += std::make_shared< TypedService >(typeid(IContainer));

        componentRegistry_->addRegistration(std::make_shared< ComponentRegistration >(
            LifetimeScope::selfRegistrationId,
            std::make_shared< ContainerActivator >(shared_from_this()),
            std::make_shared< CurrentLifetimeScope >(),
            InstanceSharing::None, // this instance will actually be shared, but this prevents shared pointer circular references
            InstanceOwnership::ExternallyOwned,
            services,
            std::unordered_map< std::type_index, std::shared_ptr< ITypeCaster > >()));

        rootLifetimeScope_ = std::make_shared< LifetimeScope >(componentRegistry_);
        rootLifetimeScope_->initialize();
    }

} // namespace Hypodermic
{'fraction_non_alphanumeric': 0.11053663754679978, 'fraction_numerical': 0.0, 'mean_word_length': 3.54251012145749, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 66, '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': '2192302', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1455, 'n_words': 258}