我正在设计一个可重用的类库,其中包含2个名为core.xml.dll和core.string.dll的程序集(以及其他程序集).
xml程序集引用字符串程序集以使用某些字符串帮助程序方法.
但是现在有一个字符串方法可以从使用xml程序集中包含的方法中受益.
如果我从字符串程序集引用xml程序集,我将创建一个循环依赖项,并且无法从源代码构建两个程序集.(即鸡肉和鸡蛋问题).
为了遵循"不要重复自己"的原则,我希望避免重复两个程序集中的功能.如果我在实现中发现错误,我只想在一个地方修复它.
虽然我可以将组件合并为一个,但这并不理想,因为它会降低组件的内聚性.
我需要重新构建和重新部署整个程序集,只是为了对特定类进行小的更改.而且,最终,有这么多的依赖关系,我可能会最终得到一个巨大的库程序集.
因此,在可重用的库集合集的上下文中,这里使用的最佳方法是什么?另外,.NET框架本身如何处理这个问题?
(在Reflector中,似乎System.Configuration.dll引用System.XML.DLL,反之亦然.这实际上是否正确,如果是这样,如何管理循环依赖?)
我目前正在编写一些类来处理PHP Web应用程序中的本地化.
课程是:
整个应用程序正常运行,但我需要向Timezone添加更多内容.
这导致了这个问题:Locale需要Timezone的方法,这需要LocaleData的方法,这需要Locale的方法.
我怎样才能打破这种循环依赖?我应该把课程分成小块吗?有没有处理这个问题的模式?
干杯:)
我正在改变我的Asp.Net MVC3项目,使用Autofac将服务注入我的控制器.到目前为止,这一直非常简单.我的服务都有一个Telerik OpenAccess db属性,我通过构造函数注入(在服务基类中).而且我的控制器都有服务的构造函数属性,这些属性也会被注入.
我有一个名为AuditInfo的类,它封装了控制器的可审计属性:
public class AuditInfo
{
public string RemoteAddress { get; set; }
public string XForwardedFor { get; set; }
public Guid UserId { get; set; }
public string UserName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的服务类中的OpenAccess db属性需要将一个此类的实例注入其中,以便在各种数据库调用中用作审计信息.
问题是这不是可以在Application_Start实例化的类,因为至少有两个属性RemoteAddress和XForwardedFor在OnActionExecuting的最早阶段填充,即一旦存在Request变量.
因此,我在我的BaseController类的OnActionExecuting方法中实例化这样:
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
db.AuditInfo = AuditInfo;
}
public AuditInfo AuditInfo
{
get
{
return new AuditInfo()
{
RemoteAddress = this.Request.ServerVariables["REMOTE_ADDR"],
XForwardedFor = this.Request.ServerVariables["X_FORWARDED_FOR"],
UserId = this.UserId,
UserName = this.UserName
};
}
}
Run Code Online (Sandbox Code Playgroud)
所以 - …
dependency-injection circular-dependency inversion-of-control autofac asp.net-mvc-3
我正在用Java编写一个复杂的GUI,其中有许多组件在几个屏幕上工作,并与共享的逻辑和模型进行交互.显然,"gui"和"controller/logic"之间存在一些循环依赖关系:GUI中的用户操作被转发到控制器,控制器执行某些任务,然后需要在所有GUI中反映这些更改.在后台可能会发生一些事情,使控制器推送更新到GUI.等等.
现在,这是我的问题.监听器或观察器模式非常适合将更新推送到GUI.可以让我的GUI直接依赖于具体的控制器类吗?为什么/为什么不呢?有(并且总是会)只有一个这样的控制器.有像十几控制器调用的图形用户界面需要轮询状态和执行行动 - 我不爱的平凡回调接口少数那总是要的想法只有一个实现,也不是一个巨大的回调接口为所有各种行动.
在我的工作中(90%是Java,但我确信这个问题适用于其他语言)我经常创建两个彼此"了解"的类.更具体地说,A类导入B,B类导入A类,两者都有另一种类型的成员或局部变量.
这被认为是糟糕的设计吗?如果你愿意,反模式?
我知道之前已经提出了类似的问题,但在做完我的研究之后,我仍然对循环标题包含问题.
//FooA.h
#ifndef H_FOOA
#define H_FOOA
#include "foob.h"
class FooA{
public:
FooB *fooB;
};
//FooB.h
#ifndef H_FOOB
#define H_FOOB
class FooA;
class FooB{
public:
FooA *fooA;
};
Run Code Online (Sandbox Code Playgroud)
现在,如果我有两个循环依赖项,这就是我在stackoverflow上看到人们解决问题的方式.我唯一的问题是在我的main.cpp中我必须先包含fooa.h然后再包含foob.h
//main.cpp the right way
#include "fooa.h"
#include "foob.h"
//main.cpp that will surely get a compile error
#include "foob.h"
#include "fooa.h"
Run Code Online (Sandbox Code Playgroud)
现在我的问题是"有没有办法以某种方式转发声明这些类,这将使我不关心我在main.cpp中包含头文件的顺序?"
我正在开发旅行管理应用程序.有问题的设计如下:
旅游中的每个人都被指定为旅行者.每位旅行者都有护照.现在,旅行者可以是主会员或子会员,具体取决于他是否是家庭主管.MainMember决定像TourPackage这样的东西,他的旅行家庭的总金额等.一个SubMember在旅行时依赖于MainMember.因此,如果删除了MainMember,则还必须删除其所有子成员.
所以,旅行者有护照.(一对一关系)旅行者是主会员或子会员.(Traveler-MainMember和Traveler-SubMember之间的一对一/一)MainMember可能有几个SubMembers.(一对多)子成员只有一个主要成员.(多到一个)
我目前的ERD如下.

如您所见,三个表 - Traveler,MainMember和SubMember - 形成了循环依赖.不过,我不确定它是否会伤害我的应用程序.如果我删除作为MainMember的Traveler,则1.删除Traveler中的记录.2.删除其相关的MainMember记录.3.删除依赖于MainMember的SubMember记录.4.删除子成员的旅行者记录.
虽然它似乎不是问题,但由于Traveler-MainMember删除将始终只删除Traveler-SubMember(s).不过,我对此感觉不好.
任何人都可以指导我更好的设计吗?
更新 -
在等待回复的同时,我根据@ Daveo的回复提出了另一种设计.基本上,Traveler包含自引用外键.SubMember记录将使用它来识别他们的父母.
这是ERD.

现在,正如@Branko指出的那样,我之前的设计中没有循环依赖问题,我想知道哪种设计更好?
另外,通过Hibernate实现哪种设计会更好?我认为第二种方法可能会在通过Hibernate实现时导致复杂性.
我还要感谢关于您喜欢的设计的实现模式(Hibernate实体中的继承等)的一些指示.
database-design erd circular-dependency hibernate-mapping class-table-inheritance
我的'干净架构'Android应用程序中有3个gradle模块:'data','domain'和'presentation'."数据"和"呈现"都取决于"域名",但不是彼此.'presentation'保存Application类实现,'data'保存一些存储库单例的实现.
我想使用Dagger 2在Application中实例化存储库,但在这种情况下,我需要在'data'和'presentation'之间建立间接gradle依赖关系.从Clean架构的角度来看,这种依赖性看起来很丑陋,使得可以从"表示"访问"数据".将Dagger组件和模块代码放在单独的gradle模块'di'中会创建循环gradle依赖'data' - >'di' - >'data'.
有没有正确的方法将所有DI代码移动到单独的模块中?
android circular-dependency gradle dagger-2 clean-architecture
我目前正在研究Angular2的一个应用程序.我有3个功能模块,其中包含其他子功能模块.我想将要素1的子要素模块加载到要素2的子要素模块中,反之亦然.下面是示例代码.
行动routing.module.ts
const routes: Routes = [
{
path: '',
component: ActionComponent,
children: [
{
path: ':id',
loadChildren: 'app/action/action-detail/action-detail.module#ActionDetailModule'
}
]
}
];
Run Code Online (Sandbox Code Playgroud)
动作细节routing.module.ts
const routes: Routes = [
{
path: '',
component: ActionDetailComponent,
},
{
path: 'topic-detail/:id',
loadChildren: 'app/topic/decision-topic-detail/decision-topic-detail.module#DecisionTopicDetailModule',
}
]
Run Code Online (Sandbox Code Playgroud)
话题routing.module.ts
const routes: Routes = [
{
path: '',
component: TopicComponent,
children: [
{
path: ':id',
loadChildren: 'app/topic/decision-topic-detail/decision-topic-detail.module#DecisionTopicDetailModule'
}
]
}
];
Run Code Online (Sandbox Code Playgroud)
决策主题的细节routing.module.ts
const routes: Routes = [
{
path: '',
component: DecisionTopicDetailComponent,
},
{
path: 'action-detail/:id',
loadChildren: …Run Code Online (Sandbox Code Playgroud) 我有一个相互依赖的RadioButtonComponent和一个RadioButtonGroupDirective:
RadioButtonComponent:
import { RadioButtonGroupDirective } from "./radio-button-group.directive";
...
constructor(@Optional() @Inject(forwardRef(() => RadioButtonGroupDirective)) radiobuttonGroup: RadioButtonGroupDirective, ...) {
Run Code Online (Sandbox Code Playgroud)
RadioButtonGroupDirective:
import { RadioButtonComponent } from "./radio-button.component";
...
@ContentChildren(forwardRef(() => RadioButtonComponent))
private radioButtons: QueryList<RadioButtonComponent>;
Run Code Online (Sandbox Code Playgroud)
使用angular-cli中的最新webpack更新,我在构建时会收到以下警告:
WARNING in Circular dependency detected:
lib\controls\radio-button\radio-button-group.directive.ts -> lib\controls\radio-button\radio-button.component.ts -> lib\controls\radio-button\radio-button-group.directive.ts
WARNING in Circular dependency detected:
lib\controls\radio-button\radio-button.component.ts -> lib\controls\radio-button\radio-button-group.directive.ts -> lib\controls\radio-button\radio-button.component.ts
Run Code Online (Sandbox Code Playgroud)
事实上,代码是有效的,因为我forwardRef()在两种情况下都使用,指定其他类可能尚未加载.但是我该如何解决警告?
通常,我会为两个类中的一个实现一个接口并使用它,但是既不能@Inject也@ContentChildren不能使用接口,对吧?