Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for non-public ctor in DefaultObjectFactory (attempt no. 2 ;-)) #119

Closed
wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Jan 30, 2015

No description provided.

support for non-public ctor
fixed bug introduced by previous commit
@aaubry
Copy link
Owner

aaubry commented Jan 30, 2015

Are you sure this is a good idea?
The DefaultObjectFactory is a simple and default implementation of IObjectFactory. I don't think that it should be able to call private constructors.
It is easy to replace the implementation of IObjectFactory with another. Therefore, I think if an application has special needs regarding object instantiation, it should provide its own implementation of the interface.

@ghost
Copy link
Author

ghost commented Jan 30, 2015

Well, I am kind of used to serializers (like JSON.NET or the WCF DataContractSerializer) to invoke private ctors by default. This facilitates better encapsulation in some situations.
The only possible issue I see here is a slight performance penalty through reflection - one solution for that could be to make the behavior configurable.
Anyway, I wouldn't mind rolling my own IObjectFactory impl, but then I'd have to copy & paste the logic for resolving collection interfaces to implementations (which I also need in my application - again, for encapsulation). And duplicate code is usually a bad thing, even if it's semi-trivial. Maybe it would be a good idea to somehow factor out that logic, e.g. into an abstract base class?

@EdwardCooke
Copy link
Collaborator

This feature was already implemented in a different, opt in way. This PR also appears to be abandoned, it's over nearly 7 years old. I'm going to close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants