Take the 2-minute tour ×

I'm using c# and the unity IOC container.

I have come up with a situation where I need to register multiple objects with the same interface. In this situation how do I register/resolve these required objects from unity?

For example I need 2 different versions of the logger in the same viewmodel

Class DatabaseLogger : Ilogger {...} Class FileLogger : Ilogger {...}

How can I register and resolve these both in my viewmodel?

I could do the following :

Class DatabaseLogger : IDatabaseLogger {...} Class FileLogger : IFileLogger {...}

Is this the best way?

share|improve this question
add comment

1 Answer

log4net or the Enterprise Library Logging Application Block have their own means to write output to multiple targets (file, eventlog, database, console, ...).

I would expect this functionality from any other mature logging library out there as well. Its just a matter of the configuration of these frameworks where your messages end up.

Thus you would not need to create your own logger classes. And creating interfaces with just a single implementation (IFileLogger, IDatabaseLogger, IEventLogLogger, IConsoleLogger, ...) makes the interface pretty useless as a means of abstraction.

If you don't use such a library you might consider switching to a proven solution instead.

share|improve this answer
add comment

Your Answer


