Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Kipon.Dynamics.Plugin/DI/PluginContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class PluginContext : IPluginContext
private ITracingService TracingService;
private IOrganizationService OrganizationService;

internal PluginContext(string unsecureConfig, string secureConfig, IPluginExecutionContext pluginExecutionContext, ITracingService tracingService, IOrganizationService organizationService, CrmEventType eventType, Guid userid, System.Collections.Generic.Dictionary<Type, object> _di)
internal PluginContext(string unsecureConfig, string secureConfig, IPluginExecutionContext pluginExecutionContext, ITracingService tracingService, IOrganizationService organizationService, CrmEventType eventType, Guid userid, System.Collections.Generic.Dictionary<Type, object> _di, Type callingType)
{
this.UnsecureConfig = unsecureConfig;
this.SecureConfig = secureConfig;
Expand All @@ -28,6 +28,7 @@ internal PluginContext(string unsecureConfig, string secureConfig, IPluginExecut
this.EventType = eventType;
this.UserId = userid;
this.di = _di;
serviceFactory.RegisterExternalExports(callingType);
}

public string UnsecureConfig { get; private set; }
Expand Down
20 changes: 20 additions & 0 deletions Kipon.Dynamics.Plugin/DI/ServiceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ private ServiceFactory()
exports = GetTypesWithExportAttribute();
}

public void RegisterExternalExports(Type callingType)
{
var assembly = callingType.Assembly;
var exportAttribute = typeof(Export);
var result = new Dictionary<Type, Type>();
foreach (Type type in assembly.GetTypes())
{
var ea = type.GetCustomAttributes(exportAttribute, true).SingleOrDefault() as Export;
if (ea != null)
{
if (!exports.ContainsKey(ea.Type))
{
exports.Add(ea.Type, type);
}

}
}

}

public static ServiceFactory Instance
{
get
Expand Down
6 changes: 5 additions & 1 deletion Kipon.Dynamics.Plugin/Plugins/AbstractBasePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ public abstract class AbstractBasePlugin : IPlugin
public string UnsecureConfig { get; private set; }
public string SecureConfig { get; private set; }

private Type _callingType;

#region constructors
public AbstractBasePlugin() : base()
{
// The plugin services may exist in an external assembly so hold the calling type to register external exports with the DI container
_callingType = this.GetType();
}

public AbstractBasePlugin(string unSecure, string secure) : base()
Expand Down Expand Up @@ -49,7 +53,7 @@ public void Execute(IServiceProvider serviceProvider)

try
{
var pc = new DI.PluginContext(this.UnsecureConfig, this.SecureConfig, context, tracingService, service, et, context.UserId, di);
var pc = new DI.PluginContext(this.UnsecureConfig, this.SecureConfig, context, tracingService, service, et, context.UserId, di, _callingType);
di.Add(typeof(IServiceProvider), serviceProvider);
di.Add(typeof(IOrganizationServiceFactory), serviceFactory);
di.Add(typeof(IPluginExecutionContext), context);
Expand Down