boost-ext / di

C++14 Dependency Injection Library
https://boost-ext.github.io/di
1.13k stars 136 forks source link

Bug unique_ptr type plus di:unique scope turns out singleton #524

Open cantoo opened 2 years ago

cantoo commented 2 years ago

Expected Behavior

unique objects

Actual Behavior

singleton object

Steps to Reproduce the Problem

#include <boost/di.hpp>
#include <memory>
#include <iostream>

namespace di = boost::di;

class interface {
 public:
  virtual ~interface() noexcept = default;
};

class implement : public interface {};

static const auto injector = di::make_injector(
  di::bind<interface>.to<implement>().in(di::unique)
);

int main() {
  auto a1 = injector.create<std::unique_ptr<interface>>().get();
  auto a2 = injector.create<std::unique_ptr<interface>>().get();

  std::cout << a1 << std::endl << a2 << std::endl;
}

Specifications