IApplicationContext Interface
Used to configure a dependency injection container and activate a registered service to act as the root of an application.
public interface IApplicationContextMethods
Section titled “Methods”IApplicationContext.Create(Action<IContainer>) Method
Section titled “IApplicationContext.Create(Action<IContainer>) Method”Creates an application context using the default container.
var app = IApplicationContext.Create((container)=>{
container .Use<ISomeService,ISomeImplementation>(); .Use<ISomeOtherService,ISomeOtherImplementation>();
});
var myApp = app.Start<ISomeService>();static HAKOM.DependencyInjection.Core.Net.Api.IApplicationContext Create(System.Action<HAKOM.DependencyInjection.Core.Net.Api.IContainer> containerConfigurator);Parameters
Section titled “Parameters”containerConfigurator System.Action<IContainer>
Register any dependencies within this action.
Returns
Section titled “Returns”IApplicationContext
The IApplicationContext that can be used to activate any registered type.
IApplicationContext.Create<TContainer>(Action<TContainer>) Method
Section titled “IApplicationContext.Create<TContainer>(Action<TContainer>) Method”Creates an application context based on the given container type. Allows configuration of the container using the given action.
static HAKOM.DependencyInjection.Core.Net.Api.IApplicationContext Create<TContainer>(System.Action<TContainer> containerConfigurator) where TContainer : class, HAKOM.DependencyInjection.Core.Net.Api.IContainer, new();Type parameters
Section titled “Type parameters”TContainer
The type of container to use.
Parameters
Section titled “Parameters”containerConfigurator System.Action<TContainer>
Register any dependencies within this action.
Returns
Section titled “Returns”IApplicationContext
The IApplicationContext that can be used to wire up any registered class.
IApplicationContext.Create<TContainer>(TContainer) Method
Section titled “IApplicationContext.Create<TContainer>(TContainer) Method”Creates an application context based on the given container.
var container = new AutoFacContainer(); //must implement IContainer
container .Use<ISomeService,ISomeImplementation>(); .Use<ISomeOtherService,ISomeOtherImplementation>();
var app = IApplicationContext.Create(container);
var myApp = app.Start<ISomeService>();static HAKOM.DependencyInjection.Core.Net.Api.IApplicationContext Create<TContainer>(TContainer container) where TContainer : class, HAKOM.DependencyInjection.Core.Net.Api.IContainer;Type parameters
Section titled “Type parameters”TContainer
The type of container to use.
Parameters
Section titled “Parameters”container TContainer
The container to use.
Returns
Section titled “Returns”IApplicationContext
The IApplicationContext that can be used to activate any registered type.
IApplicationContext.Start<TRoot>() Method
Section titled “IApplicationContext.Start<TRoot>() Method”Tries to instantiate the given type based on all types registered with the app context’s DI container.
TRoot Start<TRoot>() where TRoot : notnull;Type parameters
Section titled “Type parameters”TRoot
The type to instantiate.
Returns
Section titled “Returns”TRoot
The instance of the requested type as resolved by the underlying container.
IApplicationContext.Start<TRoot>(TRoot) Method
Section titled “IApplicationContext.Start<TRoot>(TRoot) Method”Tries to instantiate the given type based on all types registered with the app context’s DI container.
System.IDisposable Start<TRoot>(out TRoot root) where TRoot : notnull;Type parameters
Section titled “Type parameters”TRoot
The type to instantiate.
Parameters
Section titled “Parameters”root TRoot
The instance of the requested type as resolved by the underlying container.
Returns
Section titled “Returns”System.IDisposable
An System.IDisposable that can be used to dispose of the context along
with its DI container.