Skip to content

Instantly share code, notes, and snippets.

@abelevtsov
Created July 11, 2016 10:36
Show Gist options
  • Save abelevtsov/d75bfba811ddfa1a00eda02ae24f53b2 to your computer and use it in GitHub Desktop.
Save abelevtsov/d75bfba811ddfa1a00eda02ae24f53b2 to your computer and use it in GitHub Desktop.
public abstract class PluginBase<T> : CrmPluginBase<T> where T : Entity
{
private IWindsorContainer ioc;
protected PluginBase()
: this(null, null)
{
}
protected PluginBase(string unsecure, string secure)
: base(unsecure, secure)
{
}
protected TService GetService<TService>()
{
ioc = LazyInitializer.EnsureInitialized(ref ioc, BootstrapIoC);
return ioc.Resolve<TService>();
}
private IWindsorContainer BootstrapIoC()
{
return new WindsorContainer().RegisterFromInterface<IService>(SystemOrgService);
}
}
public class SearchService : ISearch
{
public SearchService(IOrganizationService systemService)
{
SystemService = systemService;
}
private IOrganizationService SystemService { get; set; }
public IOrganizationService UserService { get; set; }
public void Search()
{
UserService.Create(new ral_search { ral_name = "test" });
}
}
public static class WindsorExtensions
{
public static IWindsorContainer RegisterFromInterface<T>(this IWindsorContainer container, IOrganizationService systemService)
{
container.Register(Classes.FromAssemblyContaining<T>()
.BasedOn<T>()
.WithService
.FromInterface()
.LifestyleTransient()
.Configure(
c =>
c.DependsOn(Dependency.OnValue<IOrganizationService>(systemService))));
return container;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment