title: Do you still need to check the parent / child pipelines to determine whether to create ICrmService or CrmService in 2015?
body: <p>We currently use MS Dynamics CRM V4 and are in the process of upgrading to 2015. I've got the task of updating some of our plugins.</p>
  
  <p>1 of the things I've come across that is a little confusing is whether I still need to do some sort of check on the stage of the pipeline to determine if it's a parent or child. As I understand it the parent and child pipelines have been merged into 1 as of 2011, so how should the following code be altered?</p>
  
  <pre><code>public CrmServiceProxy(IPluginExecutionContext context, Guid userId)
  {
      if (context.InvocationSource == MessageInvocationSource.Parent)
      {
          iCrmService = context.CreateCrmService(userId);
      }
      else
      {
          try
          {
              RegistryKey regkey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\MSCRM");
              string crmUrl = regkey.GetValue("ServerUrl").ToString();
              string crmServiceUrl = string.Concat(crmUrl, "/2007/crmservice.asmx");
              crmService = CreateCrmService(crmServiceUrl, context, userId);
          }
          catch (Exception)
          {
              throw new InvalidPluginExecutionException("Unable to create CrmServiceProxy - the service URL cannot be read from the Registry");
          }
      }
  }
  </code></pre>
  
  <p>I've made a start like this:</p>
  
  <pre><code>private readonly IOrganizationService iCrmService;
  private IOrganizationServiceFactory serviceFactory;
  
  public CrmServiceProxy(IServiceProvider serviceProvider, Guid userId)
  {
      IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
  
      serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
  
      if (context.Stage == 10) //10 should indicate it's the parent
      {
          iCrmService = serviceFactory.CreateOrganizationService(context.UserId);
      }
      else
      {
          try
          {
              RegistryKey regkey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\MSCRM");
              string crmUrl = regkey.GetValue("ServerUrl").ToString();
              string crmServiceUrl = string.Concat(crmUrl, "/2007/crmservice.asmx");
              iCrmService = serviceFactory.CreateOrganizationService(crmServiceUrl, context, userId); //doesn't work, just something I was trying
          }
          catch (Exception)
          {
              throw new InvalidPluginExecutionException("Unable to create CrmServiceProxy - the service URL cannot be read from the Registry");
          }
      }
  }
  </code></pre>
  
  <p>So, I understand that previously in V4 you needed to use CrmService for child pipelines and ICrmService for parent ones, hence the if statement to determine which pipeline it came from. However, do I still need to do this kind of check or can I just do away with the whole if statement and just create the service using ICrmService?</p>