locked
CRM 2011 IOrganizationService & IoC Windsor Castle RRS feed

  • Question

  • Afternoon

     

    Just starting with CRM 2011...I'm trying to do a simple MVC3 app which will allow me to add, edit and updated contacts in the CRM system using linq.  To make things efficient, I'm trying to use Dependency Injection with the IOrganizationService.  I've gone with the Windsor Castle Ioc but I'm running into problems with the registration of the IOrganizationService.  I'm using the NHibernate IoC tutorial @ http://docs.castleproject.org/Default.aspx?Page=Windsor-tutorial-ASP-NET-MVC-3-application-To-be-Seen&NS=Windsor&AspxAutoDetectCookieSupport=1

     

    Has anyone done this before?

     

    Regards

     

    Michael.

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.ServiceModel.Description;
    using System.Web;
    using Castle.MicroKernel.Facilities;
    using Castle.MicroKernel.Registration;
    using Castle.Windsor.Installer;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Client;
    using Microsoft.Xrm.Sdk.Query;
    
    namespace CRMSessionHandler.Plumbing
    {
        public class PersistenceFacility : AbstractFacility
        {
            public IOrganizationService service;
    
            protected override void Init()
            {
    
                var config = SetupConnection();
    
                Kernel.Register(
                    Component.For<IOrganizationServiceFactory>().UsingFactoryMethod(config),
                    Component.For<IOrganizationService>().UsingFactoryMethod(k => k.Resolve<IOrganizationServiceFactory>()));
                
            }
    
            public IOrganizationService SetupConnection()
            {
                Uri organizationUri = new Uri("http://heaprdxrm1/AdventureWorksCycles3/XRMServices/2011/Organization.svc");
                var cred = new ClientCredentials();
                OrganizationServiceProxy serviceproxy = new OrganizationServiceProxy(organizationUri, null, cred, null);
                
                return (IOrganizationService)serviceproxy; 
            }
        }
    }
    


    Monday, October 3, 2011 1:09 PM