用于c++的IoC和Factory -用于c#的Microsoft Unity的替代品

IoC and Factory for C++ - Alternative to Microsoft Unity for c#

本文关键字:用于 Microsoft Unity 替代品 Factory c++ IoC      更新时间:2023-10-16

什么是c++最常用的健壮的nugetpackage/library/framework,它与微软的c#库Unity做得差不多:http://unity.codeplex.com/?

最终结果将看起来像这样:

class IProjectRepository
{
public:
    vector<Project> GetProjects() = 0;
}
class XMLProjectRepository : IProjectRepository
{
public:
    vector<Project> GetProjects()
    {
        return // implementation
    }
}
class Application
{
public:
    Application( shared_ptr<IProjectRepository> projectRepository ) 
    // Or however this would look... 
    // projectRepository would be an instance of whatever i have registered (see below)
    {
        auto projects = this.projectRepository.GetProjects();
    }
}

在某些启动区域,我可以这样绑定:

BinderFramework::Register<IProjectRepository, XMLProjectRepository>();What is the most common use sturdy nuget package/library for C++ that does pretty much the same as the C# library by Microsoft called Unity: http://unity.codeplex.com/

我一直在寻找一段时间,但没有找到一个很好的完整和简单的解决方案。

我的想法是使用一个众所周知的框架,而不是编写我自己的蹩脚代码。

我可能来晚了一点,但你应该看看皮下注射公司。

它只是标头,它带有一个非常酷的Dsl,而且它已经在生产环境中使用了多年。