ServiceLocator.Current.GetInstance<IStudyService>() is not wokring

Mar 4, 2015 at 12:07 PM
Hi

We have an extension method to register the service as shown below

expression.MissingNamedInstanceIs.Conditional(configuration =>
{
    configuration.
      If(context =>
      {
        return (String.IsNullOrEmpty(context.RequestedName) ||
          context.RequestedName.Equals("localhost", StringComparison.OrdinalIgnoreCase) ||
          context.RequestedName.Equals(ServerInfo.HostName, StringComparison.OrdinalIgnoreCase));
      }).
      ThenIt.Is.Type<TService>();

    configuration.TheDefault.Is.ConstructedBy(buildContext =>
    {
      return buildContext.GetInstance<IServiceBuilder>().GetOutOfProcService<TContract>(buildContext);
    });
  });
we are saying return me the out of proc instance only if the key is remote host name. in detail we expected to receive in proc instance for all three calls mentioned below

IStudyService studyService = ServiceLocator.Current.GetInstance<IStudyService>(Stentor.Server.ServerInfo.HostName)

IStudyService studyService2 = ServiceLocator.Current.GetInstance<IStudyService>("localhost");

IStudyService studyService3 = ServiceLocator.Current.GetInstance<IStudyService>()

The first two calls are working as expected but when we go with empty key for third call highlighted one we are getting out of proc instead the in proc

If(context =>
      {
        return (String.IsNullOrEmpty(context.RequestedName) ||
          context.RequestedName.Equals("localhost", StringComparison.OrdinalIgnoreCase) ||
          context.RequestedName.Equals(ServerInfo.HostName, StringComparison.OrdinalIgnoreCase));
      }).
      ThenIt.Is.Type<TService>();
we have condition mentioned like if the requested key empty or localhost or hostanme return ThenIt.Is.Type<TService>();

but for empty key condition it's not working.
(String.IsNullOrEmpty(context.RequestedName) this condition is not wokring and the below code is getting executed

configuration.TheDefault.Is.ConstructedBy(buildContext =>
    {
      return buildContext.GetInstance<IServiceBuilder>().GetOutOfProcService<TContract>(buildContext);
    });
Can you please suggest what's wrong in this code or how the context has to be registered when the empty key needs to be processed

Thanks & regards

Sukumar