架构问题:共享同类库的解决方案;(Architectural questions: solutions sharing same class libraries; project promotion; forking solutions)
我非常需要了解如何使用Visual Studio 2010管理c#中的一些非常基本的架构问题,我在查找教科书和网站中的解决方案时遇到了一些麻烦。 假设我有一个MyWinForm.sln解决方案基于:MyWinForm.cs和两个类库,让我们说:a.dll,b.dll我的目标:我想重构我编写的应用程序只是为了学习C#的顺序拥有一个体面的应用程序架构。
我希望设计一个必须包含通用方法的c.dll,以便在不同的应用程序中重用它:MyWinForm和yawfs.sln(还有另一个Windows窗体解决方案),以便我可以创建对c的引用。来自两个解决方案的DLL。 我想我应该创建一个新的类库解决方案 ,以便重用它的类。 但是,据我所知,我无法添加对不同解决方案的引用:我只能在当前解决方案(当前解决方案中的不同项目)或.Net程序集中添加对程序集的引用。 我应该使用导航面板选择a.dll程序集来添加对它的引用吗? 也许有一种方法可以将现有的程序集包含在当前的解决方案中,使其与相应解决方案中执行的更改保持同步? 我不明白。
如果我想从MyWinForm中提取b.dll来提升它以便服务于c.dll的相同目的,该怎么办? 我如何将其推广为新的解决方案?
- 现在让我们说我需要分叉MyWinForm,这样我就可以拥有MyWinFormLeft.sln和MyWinFormRight.sln; 两者都将以不同于普通共享代码的方式发展。 他们将使用(和共享)相同的a.dll和b.dll程序集(相同版本),但MyWinForm.cs中的代码将开始更改。 从现有解决方案创建新解决方案的正确方法是什么?
我知道我的问题听起来很混乱,但问题来自于我试图在我和前一段时间使用的C编译器/链接器循环的联合VS和C#使用模式之间进行的比较:编译代码以获取您的库然后链接到他们无论应用需要什么。 期。
I badly need to understand how to manage some very basic architectural issues in c# using Visual Studio 2010 and I have some trouble in finding solutions in textbooks and web sites. Let's say I have a MyWinForm.sln solution which is based on: MyWinForm.cs and two class libraries, let's say: a.dll, b.dll My aim: I want to refactor the application I have coded just to learn C# in order to have a decent application architecture.
I wish to design a c.dll that must contain general purpose methods in order to reuse it in different applications: both MyWinForm and, let's say, yawfs.sln (yet another windows form solution) so that I could create a reference to c.dll from both the solutions. I guess that I should create a new class library solution in order to reuse its classes. But, as far as I know, I cannot add a reference to a different solution: I can only add references to assemblies within the current solutions (different projects within the current solution) or to .Net assemblies. Should i use the navigation panel to select the a.dll assembly to add the reference to it? Maybe there is a way to include an existing assembly to the current solution keeping it in sync with changes performed within the corresponding solution? I do not understand.
What if I wish to extract b.dll from MyWinForm promoting it in order to serve to the very same purpose of c.dll? How I can promote it as a new solution?
- Now let's say that I need to fork MyWinForm so that I'll have MyWinFormLeft.sln and MyWinFormRight.sln; both will evolve in a different manner from a common shared code. They will use (and share) the very same a.dll and b.dll assemblies (same version) but the code in MyWinForm.cs will start to change. What is the correct method to create a new solution from the existing one?
I know that my questions sound quite messy but the trouble come from the comparison I am trying to perform between the joint VS and C# usage pattern against the C compiler/linker cycle I used time ago: compile the code to get your libraries then link to them whatever application need them. Period.
原文:https://stackoverflow.com/questions/15165180
最满意答案
应用程序中的所有数据访问对象(
xxxDAOBean
)都扩展了GenericDAOBean
,GenericDAOBean
合并方法是:public T merge(T entity) { entity = em.merge(entity); return entity; }
其中
T
是实体的类型。 因此,对于post
对象(实体类型Post
),合并应该与postDao.merge(post);
All Data Access Objects in application (
xxxDAOBean
) extendGenericDAOBean
, and merging method inGenericDAOBean
is:public T merge(T entity) { entity = em.merge(entity); return entity; }
where
T
is type of an entity. So, forpost
object (entity typePost
), merging should be used withpostDao.merge(post);
相关问答
更多-
JPA与两个ManyToOne映射使用中间表(中间实体)(JPA mapping with two ManyToOne using an intermediary table (middle entity))[2022-05-23]
经过大量调查后,我发现: 它没有按预期工作,因为我将@ManyToOne和@JoinTable注释放在属性级别。 我手工创建了一个getter,并在其上添加了注释,并将它们考虑在内 它仍然无法正常工作,因为Hibernate在运行时没有在USAGE_LOG_PAGE表中找到“USER_ACTION_ID”列。 由于某种原因(我没有找到),这一栏不在可用字段中。 在实体“UsageLogPage”中添加字段“usage_action_id”时,它找到该属性,但拒绝创建映射,因为USAGE_ACTION_ID不 ... -
我猜这是使用@JsonIdentityInfo的结果。 通过使用该注释,您可以告诉它响应应该包含一个完全序列化的实例,然后返回引用该完全序列化实例的ID。 I'm guessing this is a result of using @JsonIdentityInfo. By using that annotation, you're telling it that the response should include one fully serialized instance and subsequen ...
-
JPA坚持ManyToOne(JPA Persist ManyToOne)[2022-12-31]
好吧,你可以简化你的代码,有这样的东西 @Transactional public void save(User user, String name) { Hometown hometown = getEntityManager().createQuery("SELECT h FROM Hometown h WHERE h.name = :name", Hometown.class).setParameter("name", name).getSingleResult(); if (home ... -
如何减少ManyToOne(jpa / hibernate)的查询次数(How to reduce number of queries for ManyToOne (jpa/hibernate))[2022-03-16]
您应该能够发出以下查询来实现您的目标: SELECT b FROM BuyerEntity b JOIN FETCH b.employee 您会注意到我正在应用JOIN FETCH ,它告诉Hibernate不仅要将EmployeeEntity表与BuyerEntity表连接起来,还要将数据作为对数据库的单个查询的一部分提取到关系中。 如果你想使用JPA Criteria API CriteriaBuilder cb = entityManager.getCriteriaBuilder(); Criter ... -
您无法将关系映射到@MappedSuperclass。 请在此处查看参考文档。 @MappedSuperclass允许您仅在域模型中实现继承。 从数据库的角度来看,这使它成为一个实现细节。 @MappedSuperclass可以很容易地在通常抽象的超类中对公共字段和注释进行分组,但是您无法与它建立关系。 如果你使用@Inheritance ,你可以放弃这个映射(注意我必须将GROUP更改为其他东西,因为它是大多数数据库中的保留字): BaseCustomerDemographicDetails.java i ...
-
JPA实体映射继承(JPA Entity Mapping Inheritance)[2022-10-03]
在该示例中,ClassC和ClassE都已标记为@Entity,因此使用了“每个类的层次结构”继承策略。 默认情况下,鉴别器列名称为“DTYPE”。 您可以使用'ClassC'上的'每个类的表'层次结构策略来尝试它。 但是,生成的表与“每个类层次结构表”有很大不同。 您可能希望根据域模型检查所需的继承策略。 这个链接可以很好地指导: http : //docs.jboss.org/hibernate/orm/4.2/manual/en-US/html/ch10.html Like Alan Hay sugg ... -
@OneToMany和@ManyToOne(@OneToMany and @ManyToOne)[2023-11-27]
你的问题在于你需要记住,有些比赛是“在家”,有些比赛是“离开”。 像homeTeam和awayTeam一样考虑它会比homeTeam和awayTeam更容易。 每支球队都将拥有OneToMany主场比赛和另外一场比赛的OneToMany 。 然后,您可以添加便捷方法以获取所有匹配项(如果需要)。 @Entity public class Team { @OneToMany(mappedBy="homeTeam") private SethomeMatches = new H ... -
问题1:这是一个很好的问题,但为了回答它,你需要理解owning实体的概念。 具有@ManyToOne注释的Entity是关系的所有者。 这对于开发人员来说很重要,因为除非在拥有方进行,否则不会保持任何关系,在这种情况下,这意味着设置Order.user 。 但是,由于您在非拥有User上具有cascade注释,因此您必须执行额外的工作才能使用级联功能: // create Order Order order = new Order(); // create User and Set of orders U ...
-
在JSP中使用JPA无法检索@ManyToOne映射实体的属性(Using JPA, in JSP, can't retrieve property of @ManyToOne mapped entity)[2023-07-08]
应用程序中的所有数据访问对象( xxxDAOBean )都扩展了GenericDAOBean , GenericDAOBean合并方法是: public T merge(T entity) { entity = em.merge(entity); return entity; } 其中T是实体的类型。 因此,对于post对象(实体类型Post ),合并应该与postDao.merge(post); All Data Access Objects in application (xxxDAO ... -
目前尚不清楚您想要做什么,但是如果您想要引用该集合中的最终项目,则可以使用一些可行的选项。 将集合标记为“extra-lazy”,这将允许您访问列表中的最后一项而不加载整个集合。 如果您确实需要加载集合中的其他项目,则可能会出现问题。 https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/performance.html “Extra-lazy”集合获取:根据需要从数据库中访问集合的各个元素。 除非绝对需要,否则Hibernate会尝试不将整个 ...