Factory pattern in C#: How to ensure an object instance can only be created by a factory class?

后端 未结 17 1743
小鲜肉
小鲜肉 2020-11-29 16:51

Recently I\'ve been thinking about securing some of my code. I\'m curious how one could make sure an object can never be created directly, but only via some method of a fact

17条回答
  •  醉话见心
    2020-11-29 17:05

    You could make the constructor on your MyBusinessObjectClass class internal, and move it and the factory into their own assembly. Now only the factory should be able to construct an instance of the class.

提交回复
热议问题