Checking my use of IoC in ABP with an ITransientDependency ....
See original GitHub issue- Abp 2.3.0
I want to make sure I have understood the use of ITransientDependency with how I have things implemented below:
public interface IOzCpShortCodeProcessorBase<out TProcessOutput> : ITransientDependency
{
}
public abstract class OzCpShortCodeProcessorBase<TProcessOutput> : IOzCpShortCodeProcessorBase<TProcessOutput> where TProcessOutput : new()
{
}
public interface IOzCpShortCodeCruiseListProcessor : IOzCpShortCodeProcessorBase<OzCpProcessOutput>
{
}
public class OzCpShortCodeCruiseListProcessor : OzCpShortCodeProcessorBase<OzCpProcessOutput>, IOzCpShortCodeCruiseListProcessor
{
}
public static class OzCpShortCodeHelper
{
/// <summary>
/// Factory to spin up the appropriate processor class to deal with the short code in question.
/// </summary>
/// <param name="aShortCode">Short code to be processed.</param>
/// <returns>Returns a concrete of OzCpShortCodeProcessorBase that can be used to process the short code.</returns>
public static dynamic ProcessorFactory(OzCpShortCodeParseItem aShortCode)
{
if (!aShortCode.IsValid)
throw new Exception("Short code was not correctly parsed.");
if (aShortCode.Identifier.Trim().ToUpper() == "CRUISELIST")
return IocManager.Instance.Resolve<IOzCpShortCodeCruiseListProcessor>();
throw new Exception($"I don't know how to create a processor for {aShortCode.Identifier}");
}
}
Ultimately from within an action method in an MVC application I make the following call to the factory method:
public virtual ActionResult Process()
{
//Get a short code processor from the factory and then cast to a concrete
dynamic shortCodeProcessor = OzCpShortCodeHelper.ProcessorFactory(shortCode);
//-- Cruise List ---------------------------------------------------------------------
if (shortCodeProcessor is OzCpShortCodeCruiseListProcessor)
{
OzCpShortCodeCruiseListProcessor shortCodeCruiseListProcessor = (OzCpShortCodeCruiseListProcessor) shortCodeProcessor;
OzCpProcessOutput shortCodeCruiseListProcessOutput = shortCodeCruiseListProcessor.Process(aShortCode);
TokenContentQueryBuilderCruiseListViewModel viewModel = PrepareTokenContentQueryBuilderCruiseListViewModel(new OzCpQueryBuilderKindDataCruiseList
{
CruiseCodes = shortCodeCruiseListProcessOutput.CruiseList.CruiseCodes
}, 1, 9999999);
result = OzCpCmsHelper.RenderViewToString(_ControllerContext, MVC.Cms.Views._TokenContentQueryBuilderCruiseList, viewModel);
}
//-- /Cruise List ---------------------------------------------------------------------
}
As shortCodeProcessor is marked with ITransientDependency am I correct in assuming that it will be destroyed at the conclusion of the Process() method call? (I don’t explicitly have to dispose of it).
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Dependency Injection | Documentation Center | ABP.IO
If you implement these interfaces, your class is registered to dependency injection automatically: ITransientDependency to register with transient lifetime.
Read more >Dependency Injection
Registration informs the IOC (Inversion of Control) Container (a.k.a. the DI framework) about your classes, their dependencies and lifetimes. Somewhere in your ......
Read more >Dependency Injection
With such a dependency, it's very hard (or impossible) to unit test the PersonAppService. ... You can use IocManager to register dependencies (generally...
Read more >Basic configuration of ABP framework and Dependency ...
When your application needs to create objects using the IOC container, ASP. NET provides a number of ways to resolve dependencies. Constructors ...
Read more >IShouldInitialize interface equivalent in ABP Framework
I search for an equivalent of the IShouldInitialize interface in ABP.IO framework. In ASP.NET Boilerplate, the interface marked the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
ASP.NET MVC 5
This is handled by an
IControllerFactory
.ABP sets
IControllerFactory
inAbpWebMvcModule
.IControllerFactory
asWindsorControllerFactory
.MVC system calls
IControllerFactory.ReleaseController
.WindsorControllerFactory
releases the controller.ASP.NET Core
This is handled by an
IControllerActivator
.ABP provides
AddAbp
extension to be called inStartup
.IControllerActivator
withServiceBasedControllerActivator
.WindsorRegistrationHelper.CreateServiceProvider
.IServiceProvider
asScopedWindsorServiceProvider
.IMsLifetimeScope
.IMsLifetimeScope
asMsLifeTimeScope
._resolvedInstances
.MVC system disposes
IServiceProvider
.ScopedWindsorServiceProvider
disposesIMsLifetimeScope
.MsLifeTimeScope
releases_resolvedInstances
.Thank you @acjh for your great explanation.