Beginning in v7, you can now implement your own custom naming service that will be used by XrmToolkit while generating your proxy classes. You must implement one of the following interfaces:
The most straigt forward approach to supplying your own custom naming service is to create a C# or VB.Net "Library Project" in your solution that will contain the naming service. You could also use an existing library project as well.
After creating the project, install the 'XrmToolkit.ProxyGeneration.Extensions' NuGet package. This package also has a reference to the 'Microsoft.CrmSdk.CoreTools' NuGet package so there is no need to install it separately. By installing this pacakge, it also automatically adds a reference to the 'CrmSvsUtil.exe' file, allowing you to implement the 'INamingService' interface.
The method that you use for generating your proxy classes will help determine which interface to implement for your custom naming service. If you use the 'CrmSvcUtil' method then implementing the 'Microsoft.Crm.Services.Utility.INamingService' makes the most sense. If you use the 'XrmToolkit' method then you may want to consider implementing the 'XrmToolkit.ProxyGeneration.Extensions.IProxyNamingService'. This interface implements the 'INamingService' interface but also adds some XrmToolkit specific methods like:
Create a class that implements one of the specified interfaces. If you would like to have access to the default name provided by XrmToolkit then your constructor should accept either an 'IProxyNamingService' parameter or 'INamingService' parameter depending on which interface is being implemented.
public class ProxyNamingService : IProxyNamingService { private readonly IProxyNamingService _defaultProxyNamingService; public ProxyNamingService(IProxyNamingService defaultProxyNamingService) { // Get a reference to the default naming service this._defaultProxyNamingService = defaultProxyNamingService; } // IProxyNamingService Implementation ... }
or
public class NamingService : INamingService { private readonly INamingService _defaultNamingService; public NamingService(INamingService defaultNamingService) { // Get a reference to the default naming service this._defaultNamingService = defaultNamingService; } // INamingService Implementation ... }
Then, in your mothed, call the default naming service method and perform any additional actions:
// Prepend the word 'custom_' to the name of the class for an entity public string GetNameForEntity(EntityMetadata entityMetadata, IServiceProvider services) { var defaultName = this._defaultProxyNamingService.GetNameForEntity(entityMetadata, services); if (!defaultName.StartsWith("custom_")) defaultName = $"custom_{defaultName}"; return defaultName; }
Update the settings for the solution/project so that the value for the 'Proxy class naming method' is set to one of the following:
With the custom naming service specified, you can now generate your proxy classes following the usual flow as specified here.