is there is anyway to map/register singleton, using the unity configuration file, and map it to an interface while the singleton doesn’t expose any public constructor?
Please advice,
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have use a class that exposes an internal (as a minimum) constructor if you want unity to create an instance of it. On the other hand you could write a container extension for unity that can use private constructors via reflection.
Another alternative is to write a custom class that has a public constructor and also implements the interface. It then talks to your singleton, something like:
I would prefer the extension method though, something like this code (below) should get you into the private constructor. Then you would use this container extension in you config in order to tell unity to use your extension.