IoC and Factory for C++ - Microsoft Unity for c# 的替代品
IoC and Factory for C++ - Alternative to Microsoft Unity for c#
C++ 最常见的用法是什么 nugetpackage/library/framework,它与 Microsoft 称为 Unity 的 C# 库几乎相同: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/
我已经找了一段时间了,但找不到一个完整而简单的好解决方案。
我的想法是使用众所周知的框架而不是编写我自己的不稳定代码。
我可能来晚了一点,但你应该看看 Hypodermic。
它只是 header,它带有一个非常酷的 Dsl,而且它已经在生产环境中使用了多年。
C++ 最常见的用法是什么 nugetpackage/library/framework,它与 Microsoft 称为 Unity 的 C# 库几乎相同: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/
我已经找了一段时间了,但找不到一个完整而简单的好解决方案。
我的想法是使用众所周知的框架而不是编写我自己的不稳定代码。
我可能来晚了一点,但你应该看看 Hypodermic。
它只是 header,它带有一个非常酷的 Dsl,而且它已经在生产环境中使用了多年。