Dear LLBLGen Team,
We would like to consult you about a issue that we cannot to implement with LLBLGen v5.9.1.
Development environment like this;
Oracle DB, generate source code target framework is .NET Standard, project IDE for source code is Visual Studio 2022 and LLBLGen version 5.9.1
We aim to use DLL's created by LLBLGen in projects with different frameworks(like .NET Framework 4.8 and .NET 6). So we needed a dependency injection mechanism in LLBLGen. Our main goal was to read the information in the HttpContext object from 2 separate projects using common LLBLGen DLLs. You can see how we progressed below and we used the following document which does the following.(https://www.llblgen.com/Documentation/5.3/LLBLGen%20Pro%20RTF/using%20the%20generated%20code/gencode_usingdi.htm#instance-type-example)
We added property named as "RotaHttpContextToUse" in IEntity interface (It's inside one interface that created by us with seperated project IRotaHttpContext)
public interface IEntityCore : IEditableObject, IActiveContextParticipant, ITransactionalElement
{
IAuditor AuditorToUse { get; set; }
// We added this property
IRotaHttpContext RotaHttpContextToUse { get; set; }
// other LLBLGen codes
And we implemented the property here in the following class EntityCore;
public abstract partial class EntityCore < TFields >: IEntityCore, INotifyPropertyChanged, IEntityCoreInternal, IXmlSerializable, IDataErrorInfo, ISerializable, IDeserializationCallback
where TFields: IEntityFieldsCore {
// ...
// some codes
private ITypeDefaultValue _typeDefaultValueProvider;
private IAuthorizer _authorizerToUse;
private IAuditor _auditorToUse;
private IRotaHttpContext _rotaHttpContextToUse; // we added this line
[Browsable(false)]
public IRotaHttpContext RotaHttpContextToUse {
get {
return _rotaHttpContextToUse;
}
set {
_rotaHttpContextToUse = value;
}
}
//some codes
We added the following to the global.asax file of our project ( WebForm created with .net fw 4.8 ) in Application_Start method for register our class;
RuntimeConfiguration.SetDependencyInjectionInfo(new List<Assembly>() { typeof(RotaHttpContext).Assembly },new List<string>() { "Interface48Imp" });
And RotaHttpContext class looks below (this class generated by target framework .net framework 4.8 with WebForm);
[DependencyInjectionInfo(typeof (IEntityCore), "RotaHttpContextToUse")]
public class RotaHttpContext: IRotaHttpContext
{
//some codes
}
With this implementation we were able to read property from RotaHttpContext in runtime. As you can see below we need this class on CommonEntityBase.cs and with above DI mechanism we can access GetUserId property in RotaHttpContext class.
RotaHttpContextToUse.GetUserId()
Everything was as we wanted so far. This implemantation worked for Entity classes. Now we want to use the GetUserId() property (in RotaHttpContext) for collection objects as well. For this purpose we added below code inside to IEntityCollectionCore
IRotaHttpContext RotaHttpContextToUse { get; set; }
And changed the part below to;
[DependencyInjectionInfo(typeof(IEntityCollectionCore), "RotaHttpContextToUse")]
public class RotaHttpContext : IRotaHttpContext
{
//some codes
}
With this change, we thought that we could use this property in collection classes as well. But it didn't turn out as we expected. We cannot access to GetUserId property because RotaHttpContextToUse always comes up NULL. I think for collection classes we didn't implement DI mechanism but I don't undertand why.
Below is the part we are trying to access from the collection class.
public void SetTransferObjects(Rota.DataTransfer.DokKonsKonteynerYukuTransferObjectList transferObjectList)
{
var rotaHttpContextToUse = RotaHttpContextToUse.GetUserId();
//some codes
}
We couldn't understand why we couldn't use this method over Collection classes as it is in Entity classes, we request your help on this matter.
My CustomerId: 19501
Best regards.