Using structuremap with log4net wrapper

后端 未结 3 1346
南笙
南笙 2020-12-13 11:34

I have the following interface:

public interface ILogger
{
    void Debug(string message, params object[] values);
    void Info(string message, params objec         


        
3条回答
  •  长情又很酷
    2020-12-13 12:01

    If the type parameter is context-specific, I don't think this is going to work as shown. If you need to pass something context specific in the constructor, you are likely going to have to create a factory interface and implementation that returns an instance of the ILogger:

    public interface ILoggerFactory
    {
        ILogger Create(Type type);   
    }
    
    public class LoggerFactory : ILoggerFactory
    {
        public ILogger Create(Type type)
        {
            return new Log4netLogger(type);
        }
    }
    

    It might be possible to bootstrap StructureMap to supply the instance you want based on the type, but that assumes a limited number of types that you know in advance.

提交回复
热议问题