Inherited interface hides parent in Orchard framework - orchardcms

I created an interface ISecureStorageProvider like below.
public interface ISecureStorageProvider : IStorageProvider
{
}
Concrete implementation for ISecureStorageProvider looks like below.
public class SecureAzureBlobStorageProvider : AzureFileSystem, ISecureStorageProvider
{
}
What I found was, the class SecureAzureBlobStorageProvider gets injected for both the interfaces ISecureStorageProvider , IStorageProvider. But, I want both of them to be available, not one suppressing another.

Related

IoC container struggles with generics

I have an existing program with some plugin infrastructure that currently relies on plugin classes having parameterless constructors. I'd like to offer plugin authors the opportunity to just require some infrastructure from my program by specifying parameters for the constructor.
Internally, I use some generic wrapper class to encapsulate the plugin's classes and to make them behave to the rest of my program like older pre-plugin era internal classes.
I have some placeholder here representing my infrastructure:
public interface IInfrastructure
{
}
public class Infrastructure : IInfrastructure
{
}
Some plugin interface specification:
public interface IPlugin
{
}
the plugin implementation requiring my infrastructure:
public class Plugin : IPlugin
{
public Plugin(IInfrastructure _)
{
}
}
and my generic wrapper class expecting some plugin class
public class PluginWrapper<TImpl> where TImpl: class, IPlugin
{
public PluginWrapper(TImpl _)
{
}
}
After registering the involved types:
ServiceLocator.Default.RegisterType<IInfrastructure, Infrastructure>(RegistrationType.Transient);
ServiceLocator.Default.RegisterType(typeof(Plugin),typeof(Plugin), RegistrationType.Transient);
var wrapperType = typeof(PluginWrapper<>).MakeGenericType(typeof(Plugin));
ServiceLocator.Default.RegisterType(wrapperType, wrapperType,RegistrationType.Transient);
I find out that I can resolve the "inner" plugin type:
Assert.NotNull(ServiceLocator.Default.ResolveType<Plugin>());
but I can't resolve the "Wrapper" type.
Assert.NotNull(ServiceLocator.Default.ResolveType<PluginWrapper<Plugin>>());
Am I hitting a limitation of Catel's IoC container, or am I doing something wrong?
When not using the generic registration method, I passed the registration type in the position of the "tag" parameter by accident.
So, changing the registration part to this version:
ServiceLocator.Default.RegisterType<IInfrastructure, Infrastructure>(RegistrationType.Transient);
ServiceLocator.Default.RegisterType(typeof(Plugin),typeof(Plugin),registrationType:RegistrationType.Transient);
var wrapperType = typeof(PluginWrapper<>).MakeGenericType(typeof(Plugin));
ServiceLocator.Default.RegisterType(wrapperType, wrapperType, registrationType:RegistrationType.Transient);
fixes the problem and everything goes as expected.

Is possible to have a different tag name in winui 3 user control?

Is it possible to have a different tag name fo my user control?
My class looks like:
public sealed partial class ValidationControl : UserControl { ... }
and used like this:
<controls:ValidationControl Model="{x:Bind ViewModel, Mode=OneWay}" PropertyName="Name"/>
Is there some property in my user control that could change the tag name but that my class' name will continue naming ValidationControl?:
<controls:Validation Model="{x:Bind ViewModel, Mode=OneWay}" PropertyName="Name"/>
I have another class named Validation, that's why I cannot name only Validation to my control.
You could create a one-liner marker type:
public class AlternativeName : ValidationControl { }
...and instantiate this one instead of the base class:
<controls:lternativeName ...
Don't forget to also remove the sealed keyword from the definition of the existing ValidationControl class:
public partial class ValidationControl : UserControl { ... }

Override BQL used for PXProjection on SOShipmentPlan

I have a need to override the Select statement being used for the SOShipmentPlan PXProjection/DAC, namely, removing the
And <INPlanType.isFixed, Equal<boolFalse>
condition.
I can override all of the CreateShipment() logic and bring in any other necessary routines into an SOShipmentEntry_Extension class, to the point where I finally can use my own version of a SOShipmentPlan class, but that all seems needlessly complex when all I want to do is override the select for the PXProjection attribute. Overriding CreateShipment() and supporting routines also seems like a quick way to get in trouble come time for upgrades.
So, is there an easy way to override the PXProjection's BQL, or am I stuck overriding all kinds of code?
UPDATE 1
Based on a link provided below (stackoverflow.com/a/41540659/7376238), I feel like I'm close. Here's the block of code I end up with:
namespace PX.Objects.SO
{
public class SOShipmentEntry_Extension : PXGraphExtension<SOShipmentEntry>
{
#region Event Handlers
#endregion
[Serializable]
[PXProjection(typeof(Select2<SOOrder,
InnerJoin<SOOrderType, On<SOOrder.FK.OrderType>,
InnerJoin<INItemPlan, On<INItemPlan.refNoteID, Equal<SOOrder.noteID>>,
InnerJoin<INPlanType, On<INItemPlan.FK.PlanType>>>>,
Where<INItemPlan.hold, Equal<boolFalse>,
And<INItemPlan.planQty, Greater<decimal0>,
And<INPlanType.isDemand, Equal<boolTrue>,
And<INPlanType.isForDate, Equal<boolTrue>,
And<Where<INItemPlan.fixedSource, IsNull,
Or<INItemPlan.fixedSource, NotEqual<INReplenishmentSource.transfer>>>>>>>>>))]
[PXSubstitute()]
public partial class SOShipmentPlanCst : SOShipmentPlan
{
int x = 0;
}
}
But it doesn't seem to work. Not sure of where I'm supposed to put the code. I've tried putting the class definition inside and outside of public class SOShipmentEntry_Extension : PXGraphExtension<SOShipmentEntry> class (currently inside the extension class as shown). No luck either way.
THIS ANSWER DIDN'T WORK
Fair warning... I have not done this to a PXProjection before, so you'll have to see if this works. The nature of extensions tends to allow overriding views by simply redefining them. I have not done this myself with a projection, but I suspect it will be similar. Give it a try and see if you get the desired results. All I can say about testing it is that "it compiled" when I added to my project and removed the INItemPLanType.isFixed condition.
public class SOShipmentEntry_Extension : PXGraphExtension<SOShipmentEntry>
{
[PXProjection(typeof(Select2<SOOrder,
InnerJoin<SOOrderType, On<SOOrder.FK.OrderType>,
InnerJoin<INItemPlan, On<INItemPlan.refNoteID, Equal<SOOrder.noteID>>,
InnerJoin<INPlanType, On<INItemPlan.FK.PlanType>>>>,
Where<INItemPlan.hold, Equal<boolFalse>,
And<INItemPlan.planQty, Greater<decimal0>,
And<INPlanType.isDemand, Equal<boolTrue>,
And<INPlanType.isForDate, Equal<boolTrue>,
And<Where<INItemPlan.fixedSource, IsNull, Or<INItemPlan.fixedSource, NotEqual<INReplenishmentSource.transfer>>>>>>>>>))]
public partial class SOShipmentPlan : IBqlTable { }
}

Calling one specific overriden method in all derived classes

Consider the following code:
// ======== Abstract class ========
public abstract class Creatures {
public abstract void loseEnergy();
public void execute()
{
loseEnergy();
}
}
// ======== Animals ========
public class Animals : Creatures
{
public override void loseEnergy(){}
}
public class Birds : Animals
{
public override void loseEnergy(){}
}
// ======== Human ========
public class Human : Creatures
{
public override void loseEnergy(){}
}
public class Male : Human
{
public override void loseEnergy(){}
}
public class Female : Human
{
public override void loseEnergy(){}
}
[ This code was based on the code by Jayson suggested here: "Base class methods calling derived class methods ?" ]
In the given code example, I would like to have the runtime executing EACH derived class object's certain method, in this case, which is 'loseEnergy()', however, I could not find the solution.
How do I approach this problem?
What can be useful to know or to try.. in order to solve this issue?
Your help is very much appreciated!
Thank you!
Kind regards,
Segara
P.S. Some search I have done so far:
"How to call overriden methods in all derived classes"
"Collection of derived classes that have generic base class"
"How to call derived function using base class object"
"Call method of the derived class through reflection possible or no"
EDIT:
I decided to stick to the idea I had before which is to have some list that would contain the objects of the classes that have 'loseEnergy()' method. Having such list I will be able to call every object's method 'loseEnergy()', which is what I wanted.
Question can be closed.
Thank you.
I didn't really understand your problem but anyway i can try to give you some means to use abstract classes :
If you use a abstract method, you SHOULD override it in a subclasses (like a method declared in an interface)
If you want that all inherited class use a same method, you can implement it in the abstract class ; all subclasses will use the method you implements if you don't override it, you've have to not declare it in the subclasses (extends < ABS_CLASS > is good enough)
If you want use a method of the abstract class which is override in the sub class you can use the keyword super .
I hope it will help you.
if you mean that you want the calls: female.loseEnergy() -> human.loseEnergy() -> creature.loseEnergy(), call the base method in the first line of the overriden one
public class Female : Human
{
public override void loseEnergy()
{
base.loseEnergy();
// do stuff
}
}
In the Greenfoot environment that you mention in the post above, the act() method is called only on actors which have been added into the "world". Internally, this adds them into a list. The simulation process iterates through the list and calls act() on each object in turn. Objects that are not "in the world" are not known to the system and so do not have their act method called. There is no magic here going on here.
If you wanted similar behaviour but without manually adding objects into a list, you could possibly have the base class constructor add new objects into a global list. I don't know C# so I don't know precisely how to do this, but I cannot imagine it would be difficult.

running a T4 on adding a class

Using t4, I want when the developer adds a class which ends to Report keyword (e.g. CompanyReport), put some code in that class.
Imagine I create a class named CompanyReport, I want the class to be like :
public class CompanyReport : IReportItem
{
private Company _company;
public CompanyReport(Company company)
{
_company = company;
}
public ReportBookmark BookMark
{
get { return ReportBookmark.Company; }
}
public void Report(ISetBookmark wordReport)
{
}
}
Maybe you should consider using a customized ItemTemplate for Visual Studio or just a snippet. Both are quite easy to build and redistribute. I'am also not sure if it is possible to invoke some T4-Template on creating (and really ONLY on creating) a class.

Resources