In the politest way possible, you probably need to take a few steps backwards to go forwards.
So to write a plugin, you need to implement IPlugin
, which has just the one method
public void Execute(IServiceProvider serviceProvider)
The IServiceProvider
is your window into CRM and the context of the event that you are hooking into.
Typically, you would do something like:
var context = (IPluginExecutionContext) serviceProvider.GetService(typeof (IPluginExecutionContext));
var factory = (IOrganizationServiceFactory) serviceProvider.GetService(typeof (IOrganizationServiceFactory));
var service = factory.CreateOrganizationService(context.UserId);
In the example above, service
is of type IOrganizationService
. This gives you all the methods you would expect
service.Execute(foo);
service.RetrieveMultiple(bar);
service.Update(... /* etc
Might be worth reviewing some of the guides around this - as I've given in a previous answer here