Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Exception: Object reference not set to an instance of an object.
{System.NullReferenceException: Object reference not set to an instance of an object.
at System.Web.HttpContextExtensions.GetOwinEnvironment(HttpContext context)
at System.Web.HttpContextExtensions.GetOwinContext(HttpContext context)
You did not instantiate UserManager, but trying to use it as a static class which it is not.
Use the new keyword (how do I create an instance of UserManager).
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 months ago.
Improve this question
I've just integrated a new devteam, which is using grails. I'm new to grails/groovy too, so the question is possibly stupid, but I need some advice.
The legacy code I'm manipulating is using a lot of StringUtils from apache, and I can't find a good point why they're doing that. I've suggested to use groovy truth instead, and avoid importing an unnecesseary class, but they keep on not correcting existing code, and using it in new code.
So, my question is : are there any advantages I did'nt see, for that use case ?
Example of code :
if (StringUtils.isNotEmpty(params.invoiceEventId)) {
invoiceEvent = InvoiceEvent.findById(params.invoiceEventId)
}
Thanks for your wisdom
Look at the source code of both solutions:
StringUtils
public static boolean isNotEmpty(final CharSequence cs) {
return !isEmpty(cs);
}
public static boolean isEmpty(final CharSequence cs) {
return cs == null || cs.length() == 0;
}
and StringGroovyMethods:
public static boolean asBoolean(CharSequence string) {
return string.length() > 0;
}
The methods are almost identical. The only difference, is that null-check in Groovy is done outside.
Ergo, there's no need to use the long call to the 3rd party library in Groovy or Grails.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Im trying to implement case_class in Ruby for academic reasons.
I have already read this question Redefining "class" keyword in Ruby
I'm having troubles to understand why def case_class is used inside a Module. Why are there two definitions of case_class?
The author of the answer says this "foo_immutable = Foo_immutable.new" works,
using the same code and irb I get
NameError: uninitialized constant Foo_inmutable
from (irb):3
from -e:1:in `load'
from -e:1:in `<main>'
Why does that happen? How should I initialize the constant?
Thanks!
First, a class is a instance of class Class, and Class inherited Module. For example:
class A
end
we defined a class A, it's class, so A is a instance of Class.
Since A is a instance of Class, it get all the instance methods in Class. And because Class inherited Module, and Module has this instance method "case_class", so, A get the method "case_class".
we can invoke like this: A.case_class. That why we defined "case_class" method in Module: in order to make all the classes have this method.
Second, these two method do not need to have the same name, the second invoke the first, by self.class.case_class(name, superclass, &blk).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Dependency Injection design pattern is said to be helpful for loose coupling, however I cannot understand how it can be achieved since the calling object has to pass the dependencies in the constructor to the service?
Please explain?
I cannot understand how it can be achieved since the calling object has to pass the dependencies in the constructor to the service?
The calling object does not have to pass the dependencies in the constructor of the service.
The calling object will have the an implementation of the service injected into its constructor like this:
public class CallingObject
{
private readonly IService m_Service;
public CallingObject(IService service)
{
m_Service = service;
}
public void DoSomething()
{
m_Service.AskForService();
}
}
The entity that is responsible for wiring all objects together is the composition root.
So its the composition root that has to pass the dependencies into the constructor to the service.
The only disadvantage I found is that highlights design problems and causes many programmers to blame dependency injection for the design problems.
I'm sure that Krzysztof Koźmic can explain it better than me. Please read this.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
In our Delphi 2007 application we are using a lot of the following constructs
FdmBasic:=TdmBasicData(FindOwnerClass(AOwner,TdmBasicData));
The FindOwnerClass travels the Owner hierarchy of the current component upwards to find a specific class (in the example TdmBasicData). The resulting object is stored in the Field variable FdmBasic. We use this primarily to pass datamodules along.
Example:
When generating a report, the resulting data is compressed and stored in a Blob field of a table accessed through a datamodule TdmReportBaseData. In a separate module of our application, there is functionality to show the data from the report in a Paged form using ReportBuilder. The main code of this module (TdmRBReport), uses a class TRBTempdatabase to convert the compressed blob data into different tables that are usable in the Reportbuilder runtime reportdesigner.
TdmRBReport has access to TdmReportBaseData for all kinds of report-related data (type of report, report calculationsettings, etc). TRBTempDatabase is constructed in TdmRBReport but has to have access to TdmReportBasedata. So this is now done using the construction above:
constructor TRBTempDatabase.Create(aOwner: TComponent);
begin
inherited Create(aOwner);
FdmReportBaseData := TdmRBReport(FindOwnerClass(Owner, TdmRBReport)).dmReportBaseData;
end;{- .Create }
My feeling is that this means that TRBTempDatabase knows a lot of its owner, and I was wondering if this is some sort of code smell or Anti-pattern.
What are your thoughts about this? Is this a code smell? If so, what is a better way?
On the description presented here I regard this as mildly smelly. However, it seems easy to fix.
I'd be inclined to pass the dmReportBaseData object into the constructor of any component that needs it. This makes the contract clear at compile time rather than enforcing it at runtime as you currently do.
As it currently stands, the contract you enforce is stronger than it needs to be. Although TRBTempDatabase only requires a dmReportBaseData instance, it will only function if it can get that instance from a TdmRBReport report object.
Making this change would also allow TRBTempDatabase and TdmRBReport to have a divorce and still function successfully. And as #Lieven points out in the comments, this would likely make testing easier.
If all you're doing in a base class is maintaining a reference to a parent object then no, it's not code-smell, it's a perfectly legitimate use. You can explicitly design a base class to carry information about "something that might come later."
If the base class is relying on some characteristic of the derived class that isn't present in itself (i.e. the generalized class relies on a specialization of one of its children) then yeah, that might be a bit funky.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
can someone suggest the ideal Unit test cases that may fit in across each of the layers .
(which otherwise can be called as a standard).
for instance, in an ASP.NET MVC applictaion using a Repository pattern -
Controller - can assert for View names and format of the data returned to the views , from the controller action methods( i couldnt think of more , if u can please suggest).
Services Layer - ?? what can be written. because they in turn depend on the layers underneath.. ( can some one suggest a Unit Case with example for sevices layer)?.
One trivial question to finish off. Irrespective of the layers , the method being tested makes calls to other instance methods/static methods say,
public List<string> MethodUnderTest()
{
instance.SomeOtherMethod();
StaticMethod();
}
in each case it is neccesary to mock the methods calls by moving that to interfaces .? any thoughts on that . ( coz unit Testing by nomenclature should not depend on anything)
Can some
I recommend reading the Art of Unit Testing. It covers this stuff in detail.