Sap Spartacus 4.3 extend ProductListComponent - spartacus-storefront

I have this constructor in my class.
export class CustomProductListComponent extends ProductListComponent implements OnInit, OnDestroy {
constructor(
protected pageLayoutService: PageLayoutService,
protected productListComponentService: ProductListComponentService,
protected scrollConfig: ViewConfig,
) {
super(pageLayoutService, productListComponentService, scrollConfig);
}
}
However, it gives me an error of
"Class 'CustomProductListComponent' incorrectly extends base class 'ProductListComponent'.
Property 'pageLayoutService' is private in type 'ProductListComponent' but not in type 'CustomProductListComponent'.ts(2415)
"
Do you know to solve the pageLayoutService since its private in base class?

Related

“control” is defined as an accessor in class 'ParentClass, but is overridden here in 'ChildClass" as an instance property

export class ChildClass extends ParentClass implements OnInit {
#Input () control: FormControl;
}
#Directive()
export abstract class ParentClass implements OnInit, OnDestroy {
get control(): AbstractControl {
return this.page && this.page. getControl(this.content.id);
}
But while doing npm start getting below error.
“control” is defined as an accessor in class 'ParentClass, but is overridden here in 'ChildClass" as an instance property.
Getting this error while migrating existing angular 10 application into angular 11.

How can I get HttpContext inside an abstract class in ASPNETCore

I have the following Repository:
public class TestRepository : WebCaller<Data>, ITestRepository
{
string connString = this.GetConnectionString();
.... some code here
}
In my Repository I can do Dependency Injection to the constructor without a problem.
In my abstract class WebCaller I need to get access to HttpContext somehow, I was reading that you can Inject IHttpContextAccessor to get access to the context, but because this is an Abstract class, that also lives outside the Web project, I can't have a constructor.
I was trying to do this:
public abstract class WebCaller<T> : WebRequest, IDisposable
{
//[Inject]
public ITestRepository TestRepo
{
get
{
return this.HttpContext.RequestServices.GetRequiredService<ITestRepository >();
}
}
..... more code here
}
Was trying to use Inject attribute but was reading that is no longer available, so should be other way to pass HttContext to the abstract class.
You can have a constructor on your abstract class. Just inject IHttpContextAccessor to it. Then any derived class will also take IHttpContextAccessor and pass it to its base constructor (your abstract class constructor). You can make the abstract class constructor protected.
Like:
public abstract class WebCaller<T> : WebRequest, IDisposable
{
protected WebCaller(IHttpContextAccessor contextAccessor)
{
}
}
public class TestRepository : WebCaller<Data>, ITestRepository
{
public TestRepository(IHttpContextAccessor contextAccessor) : base(contextAccessor)
{
}
string connString = this.GetConnectionString();
.... some code here
}

Deadbolt 2.5.0, unable to instantiate custom SubjectPresentHandler extending AbstractDeadboltHandler

I am using deadbolt 2.5.0 and I have created custom SubjectPresentHandler as below:
public class SubjectPresentHandler extends AbstractDeadboltHandler
{
public SubjectPresentHandler(ExecutionContextProvider ecProvider) {
super(ecProvider);
}
// other required methods
}
And, I also have :
#Singleton
public class CustomDeadboltHandlerCache implements HandlerCache
{
private final DeadboltHandler defaultHandler = new SubjectPresentHandler();
// other required code
}
Now the problem that I am facing here is I cannot instantiate SubjectPresentHandler using its default contructor. I get an error as: "The constructor SubjectPresentHandler is undefined". Now when I add default constructor in SubjectPresentHandler as below:
public SubjectPresentHandler() {
super();
}
I get an error as:
The constructor AbstractDeadboltHandler is undefined. If I try removing the paramaterized constructor in SubjectPresentHandler then I get error message as
"Implicit super constructor AbstractDeadboltHandler() is undefined for default constructor. Must define an explicit constructor".
I am not sure how can I resolve this, thus seeking solution regarding this issue.
The constructor of SubjectPresentHandler takes an ExecutionContextProvider as a parameter. The easiest way to do this is to inject one and have the creation of the handler done via Guice.
The ExecutionContextProvider is provided by DeadboltModule - you can see this here.
#Singleton
public class SubjectPresentHandler extends AbstractDeadboltHandler
{
#Inject
public SubjectPresentHandler(ExecutionContextProvider ecProvider) {
super(ecProvider);
}
// other required methods
}
You can also inject the handler into the handler cache:
#Singleton
public class CustomDeadboltHandlerCache implements HandlerCache
{
private final DeadboltHandler defaultHandler;
#Inject
public CustomDeadboltHandlerCache(final DeadboltHandler defaultHandler) {
this.defaultHandler = defaultHandler;
}
// other required code
}
If you have multiple handlers, take a look at the documentation for how to handle this.

Kotlin: Visibility of static nested Java class declared inside a non-visible class

Using java my static-nested java class is visible, but using Kotlin it is not. See my example below. Is there a good reason it is not allowed, or is it a bug? And are there any workarounds so that I can extend NestedStaticClass from Kotlin?
I have a package-private java class containing the static-nested class
package javapackage;
class HiddenClass {
public static class NestedStaticClass {}
}
HiddenClass is extended by a public class.
package javapackage;
public class VisibleClass extends HiddenClass{}
From my java class extending VisibleClass, I can see NestedStaticClass (It compiles)
package otherpackage;
import javapackage.VisibleClass;
public class JavaClass extends VisibleClass {
public static class C4 extends NestedStaticClass {}
public JavaClass() {
new NestedStaticClass();
}
}
But from Kotlin this does not work. I get the compile error: "Unresolved reference NestedStaticClass"
package otherpackage
import javapackage.VisibleClass
class KotlinClass() : VisibleClass() {
class C1() : NestedStaticClass()
init {
val v = NestedStaticClass()
}
}

Accessible from only one class

I have a class and a method in it. The method's access modifier is now private but it can be changed. Now i just want the method to be seen only one another class.
the other class and my class are in same directory by the way.
The only way to allow a method in a class to be available to only one other class is to use a nested private class.
public class Enclosing
{
private class InnerClass
{
public void MyMethodThatCanOnlyBeUsedByEnclosingClass()
{}
}
}