Created
July 11, 2016 10:36
-
-
Save abelevtsov/d75bfba811ddfa1a00eda02ae24f53b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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