I've create a new module for exporting and I make my module dependent from it with DependOn attribute and it work as aspected but the Ioc not inject the ILogger.
Below some part of my code. So If I don't call the Initialize() on creator ILogger still remain to NullLogger and the Initialize() never call from Ioc What I'm wrong?
public abstract class EpPlusExcelExporterBase<T> : ITransientDependency, IDisposable, IShouldInitialize
{
...
public ILocalizationManager LocalizationManager { get; set; }
public ILogger Logger { get; set; }
....
protected EpPlusExcelExporterBase()
{
AppFolders = NullAppFolder.Instance;
Logger = NullLogger.Instance;
LocalizationManager = NullLocalizationManager.Instance;
}
protected EpPlusExcelExporterBase(string localizationName)
: this()
{
LocalizationSourceName = localizationName;
Initialize();
}
public virtual void Save(ExcelPackage excelPackage, FileDto file)
{
var filePath = Path.Combine(AppFolders.TempFileDownloadFolder, file.FileToken);
excelPackage.SaveAs(new FileInfo(filePath));
}
public void Initialize()
{
AppFolders = IocManager.Instance.IocContainer.Resolve<IAppFolders>();
Logger = IocManager.Instance.IocContainer.Resolve<ILogger>();
LocalizationManager = IocManager.Instance.IocContainer.Resolve<ILocalizationManager>();
}
}
10 Answer(s)
-
0
You don't need to call the Initialize method, the framework will call it automatically.
When the framework calls the Initialize method, your property injection should be working.
-
0
mmm but I try to put a break point but it's never call ... are you sure?
So the big question is why my class ha not ILogger correctly initialize...
-
0
I am very sure.
Can you share more code? It would be best if I could reproduce your problem.
-
0
For sure. I add my module file
[DependsOn(typeof(AbpKernelModule))] public class AbpExportingModule : AbpModule { public override void PreInitialize() { IocManager.Register<IAppFolders, AppBaseFolders>(); } public override void Initialize() { //IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly()); IocManager.RegisterAssemblyByConvention(typeof(AbpExportingModule).GetAssembly()); } public override void PostInitialize() { //AppFolders = Dependency.IocManager.Instance.IocContainer.Resolve<IAppFolders>(); //Logger = Dependency.IocManager.Instance.IocContainer.Resolve<ILogger>(); //LocalizationManager = Dependency.IocManager.Instance.IocContainer.Resolve<ILocalizationManager>(); } }
-
0
@andmattia
Can you share the complete code of your project? Or simply use the Demo project to reproduce your problem.
At present, the reason for the problem cannot be analyzed based on the above code.
My email: [email protected]
-
0
@maliming
I send via email my complete module source code
-
0
Have viewed it remotely, if there is any problem, please continue to feedback.
-
0
Hi maliming
I invastigate on my code like your suggestion and now the ILogger it will be injected automaticly if I derive on application a class from AbpExport module like the code below
public class VatCheckExporter : ExcelExporter<VatChekcExcelOutDto>, IVatCheckExporter { ... }
Probably I need to extend my module to do exact what I need. So I see that is possible to inject via IocManger, but is not a god option for testing in this way
using (var excelExport = IocManager.Instance.ResolveAsDisposable<ExcelExporter<VatChekcExcelOutDto>>()) { ... }
-
0
Hi @andmattia
Is this issue resolved for you ?
-
0
Hi @ismcagdas
all information is enough to solve my issue so I close the ticket.
thank for you support