I have written a set of classes to interact with AutoCAD from an out-of-process .NET assembly, but it seems like my class architecture and interactions are unusual. I am struggling to find a better way to design these.

Some background:

I am reading data from several thousand AutoCAD drawings, collecting data from bills of materials, title blocks, and other entities. AutoCAD can be interfaced with from another process in several ways. One way is to use the AutoCAD COM type library which marshals every call and is relatively slow (about 6 seconds per drawing). A much faster way is to load a .NET dll into the AutoCAD process and execute the code there. This .NET component exposes a COM interface (lets call it IAutoCADDataReader) which you can call from the outside world. If you call a method on this interface, you can harvest the data and return an object that contains all your gathered data (call it IDomainObject). This works well and takes about 200 ms (huge improvement) since the interaction with the AutoCAD database was all in-process and you only marshaled one complicated object at the very end.

The above part of the design I am happy with. What bothers me is what I do with the IDomainObject when I get it back into my main .NET assembly. It is of course a _COMObject that I can cast to a IDomainObject, but it does not really exist in my managed assembly, it is a stub or proxy. When I read its data, it calls across the process boundary. If AutoCAD gets shut down, I will get a RPC error. I would really like this object to exist independently of its original source. The natural solution is to clone it and discard the COM object.

Now, usually a Clone method is on the object itself. This fits with SRP since who would know more about cloning than it would? That is not a solution in this case since a Clone method on this IDomainObject interface would actually execute in the AutoCAD process and just give me another COM object. So ignoring SRP, I wrote a private Clone function in the managed assembly that iterates over the various arrays and other data in the IDomainObject and returns a fully managed DomainObject (not an interface). This new object can now exist independently of AutoCAD, can do whatever I want in the managed world and will not be subject to RPC errors.

I like the end result of this convoluted process since I ended up with what I wanted in a fairly fast manner, but I cannot help but think that this is a odd way to architect such a thing. Do any of you have any suggestions on how this design can be refactored to make it less peculiar?

Another criticism that could be leveled at this type of cloning is that it fails the Open/Closed principle. If I extend any of the subtypes within the IDomainObject, the clone operation will no longer be correct. I would have to update this private clone function at that time. This really just shows how this solution works for now, but it violates several principles that will probably bite me as this project continues to evolve. As a developer of in-company software, this stuff will be used and evolved for years and it would not be good to have these bad practices at the beginning.

A relatively simple and generic method to pass .NET objects over process boundaries is to use serialization. Make sure your DomainObject is serializable, then you can implement your Clone method by serializing your object to a memory stream, and deserialize it from there within you main component out-of-process.

We used that in conjunction with memory mapped files as a form of IPC to pass a complex object hierarchy, but I am pretty sure that will work in your situation as well without this additional technical detail (and if not: convert the memory stream to a string, then the COM mechanics for passing strings between processes can be applied). This solves exactly the problems you described above: you do not need to write any code for iterating over your internal arrays (the .NET serialization “magic” will do that for you), and when extending your subtypes, there is nothing to change in your clone method.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật