Link to home
Start Free TrialLog in
Avatar of cdfllc
cdfllc

asked on

Create Instance of an Interface

I thought this would be easy :) And it probably is, but I've searched and can't find anything...
Isn't there an equivalent for "getClassForName" from Java?

I have an interface, but don't know what specific class I want to load until runtime. Sure you've heard this before. I want to grab the string of the name from the Web.config file and dynamically create a class of that type...

For example,

public static IServiceProvider GetServiceProvider()
            {
                  if (serviceProvider == null)
                  {
                        String ServiceProviderObjectName = GlobalConfigurations.ServiceProviderType;
                        serviceProvider = (IServiceProvider)Activator.CreateInstance(null,ServiceProviderObjectName );                        
                  }

                  return serviceProvider ;
            }


What am I missing? And if it's all that stuff about assemblies, etc. Could someone give me the 2 minute drill on what that stuff is...:)


Thanks!
cdfllc
ASKER CERTIFIED SOLUTION
Avatar of gena17
gena17

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cdfllc
cdfllc

ASKER

I could have sworn that I tried that!. Oh well. It works!