What is the alternative for using Activator.CreateInstance() method?

364 Views Asked by At

I am creating an object of the logger type dynamically, trying to use the concept of Reflection. My code is as follows.

public static ILogger Create(string loggerType)
{
            ILogger logger = null;

            string loggerValue = WebConfigurationManager.AppSettings.Get(loggerType);
            string[] loggerDll = loggerValue.Split(',');
            string[] loggerTypeValue = loggerDll[0].Split('.');

            Assembly asm = Assembly.Load(loggerTypeValue[0]);
            Type type = asm.GetType(loggerDll[1]);

            logger = (ILogger)Activator.CreateInstance(type);
            return logger;
}

I want to drop the use of Activator.CreateInstance() method. What is the alternative choice for me?

0

There are 0 best solutions below