web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Create sample base class for inherit it from Iplugin

(1) ShareShare
ReportReport
Posted on by 6

Hello All Experts,

Is there any sample c#.net based class which i will use in all plugin development.

e.g.

Class BaseClass:Iplugin

{

// Need sample code for this for reusability.

}

Class samplePlugin:BaseClass

{

}

can anyone help me in this.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Emre GULCAN Profile Picture
    2,379 on at

    Hi,

    You can find solution on github.com/.../JonasPluginBase , directly to "BasePlugin" class github.com/.../JonasPluginBase.cs

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hello,

    In addition to that using developers tool kit also make plugin development easy: marketplace.visualstudio.com/items

    Thanks

  • EmployeeOcta Profile Picture
    6 on at

    Hello Emre Gulcan,

    I am not able to get those links working through my web browser as those are getting blocked.

    my IT admin team has closed it .

    can you provide any other link or can  you put a sample code here?

  • Suggested answer
    Emre GULCAN Profile Picture
    2,379 on at

    Hi,

    This is a Github project and there are lot of C# class inside it, but basically you can find "base plugin" code below.

    I think your IT should give permissions for Github :)

    You can add as reference this library to your project from NuGet, please check this https://www.nuget.org/packages/Rappen.Xrm.JonasPluginBase/ or run command below on your Visual Studio Package Manager Console

    Install-Package Rappen.Xrm.JonasPluginBase

    public abstract class JonasPluginBase : IPlugin
        {
            public void Execute(IServiceProvider serviceProvider)
            {
                using (var bag = new JonasPluginBag(serviceProvider))
                {
                    var watch = Stopwatch.StartNew();
                    try
                    {
                        Execute(bag);
                    }
                    catch (Exception e)
                    {
                        bag.TraceBlockStart(e.GetType().ToString());
                        bag.trace(e.ToString());
                        bag.TraceBlockEnd();
                        throw;
                    }
                    finally
                    {
                        watch.Stop();
                        bag.trace("Internal execution time: {0} ms", watch.ElapsedMilliseconds);
                    }
                }
            }
    
            public abstract void Execute(JonasPluginBag bag);
        }
  • Suggested answer
    ARIFNIIT Profile Picture
    1,391 on at

    Sample code. you can reuse this code for Plugin. same way you can create reusable code for workflow.

    Class BaseClass:Iplugin

    {

    public IOrganizationService service{get;private set;}

    public IPluginExecutionContext context{get;private set;}

    public IOrganizationServiceFactory serviceFactory {get;private set;}

    public ITracingService tracingService {get;private set;}
    public void Execute(IServiceProvider serviceProvider)
    {
    tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
    context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    service = serviceFactory.CreateOrganizationService(context.UserId);
    this.ExecutePlugin();
    }
    public abstract void ExecutePlugin();
    }

    Class samplePlugin:BaseClass

    {

    protected override void ExecutePlugin()

    {

    Entity entity=new Entity("contact");

    entity["fullname"]="Plugin Code reusability";

    service.Create(entity);
    }

    }

    Marks As Answer If it helps you

  • EmployeeOcta Profile Picture
    6 on at

    Hello Arif,

    There seems to be some error in your code, can you help in resolving those.

  • ARIFNIIT Profile Picture
    1,391 on at

    I pasted here sample code. Can you tell me where you are getting error?

  • EmployeeOcta Profile Picture
    6 on at

    public abstract void ExecutePlugin();

    protected override void ExecutePlugin()

    these two methods

    one is public and other is protected.

  • Verified answer
    ARIFNIIT Profile Picture
    1,391 on at

    oh. sorry I forget it. Actually I write sample code here without visual studio.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans