Conversion of V2 Ninject Binding to V3 - ninject

I've been banging my head at this for about 8 hours now, and I just can't seem to find a simple explanation on how to change my custom bootstrapper for ninject (Last worked on the code back in v2.x.x.x) to the new v3.0.0.0 syntax.
I currently have the following:
public class NinjectCustomBootStrapper : NinjectNancyBootstrapper
{
protected override Ninject.IKernel GetApplicationContainer()
{
return Program.MyContainer;
}
}
in a septate class, and :
public static IKernel MyContainer
{
get { return _myContainer ?? (_myContainer = CreateKernel()); }
set { _myContainer = value; }
}
private static IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Bind<CardMonitorService>().ToSelf().InSingletonScope();
return kernel;
}
in my main program 'Program.c' in a command line app.
Iv'e since updated ninject to V3.0.0.0 only to find that there's been some breaking changes. I'll admit I don't use ninject very often (I usually use structuremap), and the only reason this project does is I didn't write it originally.
Since I've upgraded Ninject, now when the app is started up I get the following exception:
Method not found: 'Ninject.Syntax.IBindingWhenInNamedWithOrOnSyntax`1<!0>
Ninject.Syntax.IBindingToSyntax`1.ToConstant(!0)'.
After a ton of searching and researching, the closest I've been able to find is this:
http://sharpfellows.com/post/Ninject-Auto-registration-is-changing-in-version-3.aspx
Which while it points me in the right direction, still isn't quite a solution as I'm not using a custom binding generator.
So my question is this.
How do I rewrite the above so that my project once again works and the WCF service when called gets the correct singleton binding handed to it when a request comes in. Going back to ninject 2 is not an option, as other dependencies in the project that have been added have forced the v3 upgrade and these add new functionality that's been requested hence why I'm working on it.
For reference this is a .NET4 build, running on NancyFX with a self hosting WCF setup as a windows service using Topshelf to provide the SCM interface.
Cheers
Shawty
Addendum to clear things up a little
This is an existing project that was originally written sometime back, I've been asked to add some new features to the project.
As part of adding these new features I have been required to upgrade the version of Ninject being used from an earlier version to V3.0.0.0 as newer dependencies added to the project require the newer version of Ninject.
Under the previous V2 of Ninject the code I have given above worked fine, with no issues, since the project has had Ninject V3 added I now get the exception as described above.
I cannot go back to the earlier version of Ninject as that will mean not being able to add the new functionality that I'm adding.
From the research I've done so far the sharpfellows link above is the closest explanation of my issue that I've managed to find so far on the internet.
I don't use Ninject very often, so I've not got the background to know what's changed between V2 & V3 that (based on my research) is the cause of my issue.
I need to know how to change my code written under V2 (and shown above) so that it works under V3.

MissingMethodException is usually a deployment problem. You compile against a different assembly than you deploy. Check that you deployed the same version and same build.

So after a week or so it turns out that the problem was that the Nancy dev team broke binary comparability with the latest version of ninject (or vice versa) :-)
There is a GitHub pull request to fix this available at :
https://github.com/NancyFx/Nancy.Bootstrappers.Ninject/pull/6
However the next version 'Nancy.Bootstrapper.Ninject' 0.12 will be out on NuGet soon which will have the fix implemented.

Related

RDLC with .NET Core 5.0 throws error in production if I use expressions inside report creation, works fine in development

I'm using RDLC to create reports with my .NET Core Web API. I spent an entire week creating 3 reports using lots of expressions. Now after publishing the application on IIS every report fails with error
An error occurred during local report processing.;An unexpected error
occurred in Report Processing.Object reference not set to an instance
of an object
The report works fine in development. After lots of research I found the issue is with expressions. I have been struggling to find a solution for almost a day searching the entire web. Many people suggested that this is the limitation of RDLC and we can't use expressions. Without expressions there is no use of this tool for me. I can't afford to spend another week to re-create those reports using another tool. In fact I don't even know what else can I use instead of RDLC to create reports.
Any suggestion to fix these issues or an alternative to RDLC will be life saving for me....
It's been a pain to use this unstable tool, but unfortunately I'm stuck in this.
Thanks
Having .NET Core work with library from .NET framework is painful to say the least.
Thanks for the recompiled WinForms library provided by lkosson.
I managed to make this work but it looks like bandage fix more then anything.
Very Important Note!! This solution make use of WPF, WinForms version of RDLC. This limit the .NET 5 solution to Windows build only. (I can't make Web version to work, maybe someone else can)
1. Update .NET 5 project settings
Unload the .NET 5 project
Right click and Edit .csproj
Update/Add 3 lines in property group as following:
<PropertyGroup>
--><TargetFramework>net5.0-windows</TargetFramework>
<RootNamespace>Net_Core_5._0</RootNamespace>
--><UseWindowsForms>true</UseWindowsForms>
--><EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
</PropertyGroup>
Reload the project
2. Add NuGet Packages
Add and install the following packages:
Microsoft.ReportViewer.Common
Microsoft.ReportViewer.WinForms
ReportViewerCore.WinForms
3. Use .NET version's function to generate Report
This is an example for your reference,
using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.Data;
namespace NET_4._8_RDLC_Lib
{
public class ReportGenerator
{
/// <summary>
/// .NET Core use this function to render reports
/// </summary>
public static byte[] RenderReport(String reportPath, Dictionary<string, DataTable> data, string format)
{
Microsoft.Reporting.WinForms.ReportViewer v1 = new Microsoft.Reporting.WinForms.ReportViewer();
v1.LocalReport.DataSources.Clear();
//Add all datasource to the Report
foreach (KeyValuePair<string, DataTable> pair in data)
{
Microsoft.Reporting.WinForms.ReportDataSource ds = new ReportDataSource(pair.Key, pair.Value);
v1.LocalReport.DataSources.Add(ds);
}
v1.LocalReport.EnableExternalImages = true;
v1.LocalReport.ReportPath = reportPath;
return v1.LocalReport.Render(format: format, deviceInfo: "");
}
}
}
The file is just inside the bytes array.

Can I determine `IsDevelopment` from `IWebJobsBuilder`

Very much an XY problem, but I'm interested in the underlying answer too.
See bottom for XY context.
I'm in a .NET Core 3 AzureFunctions (v3) App project.
This code makes my question fairly clear, I think:
namespace MyProj.Functions
{
internal class CustomStartup : IWebJobsStartup
{
public void Configure(IWebJobsBuilder builder)
{
var isDevelopment = true; //Can I correctly populate this, such that it's true only for local Dev?
if(isDevelopment)
{
// Do stuff I wouldn't want to do in Prod, or on CI...
}
}
}
}
XY Context:
I have set up Swagger/Swashbuckle for my Function, and ideally I want it to auto-open the swagger page when I start the Function, locally.
On an API project this is trivial to do in Project Properties, but a Functions csproj doesn't have the option to start a web page "onDebug"; that whole page of project Properties is greyed out.
The above is the context in which I'm calling builder.AddSwashBuckle(Assembly.GetExecutingAssembly()); and I've added a call to Diagnostics.Process to start a webpage during Startup. This works just fine for me.
I've currently got that behind a [Conditional("DEBUG")] flag, but I'd like it to be more constrained if possible. Definitely open to other solutions, but I haven't been able to find any so ...
While I am not completely sure that it is possible in azure functions I think that setting the ASPNETCORE_ENVIRONMENT application setting as described in https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings should allow you to get whether the environment is set as production or development by injecting a IHostEnvironment dependency and checking
.IsDevelopment()
on the injected dependency.

QuickBooks API throws exception com.intuit.apache.http.HttpRequest

I am using the QuickBooks Javav3SDK2.0.3 in a java web project and trying to get list of customers as given below, however I am getting the below exception. The API expects request of type com.intuit.apache.http.HttpRequest while it is passed the HttpServletRequest.
Code:
OAuthAuthorizer oauth = new OAuthAuthorizer(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
Context context = new Context(oauth, APP_TOKEN, ServiceType.QBO, COMPANY_ID);
DataService service = new DataService(context);
Customer customer = new Customer();
List<Customer> customers = service.findAll(customer);
Iterator itr = customers.iterator();
while (itr.hasNext())
{
Customer customer2 = (Customer) itr.next();
String customerName = customer2.getFullyQualifiedName();
System.out.println(customerName);
}
Exception:
java.lang.IllegalArgumentException: This consumer expects requests of type com.intuit.apache.http.HttpRequest
I ran your code using the Javav3SDK2.0.3 and it worked fine for me. Are you sure every object you're using is from the same SDK? (2.0.3). My guess is whatever calls the authorize method on OAuthAuthorizer behind the scenes is passing in the HTTPServeletRequest instead of the com.intuit.apache.http.HttpRequest due to some sort of sdk version mismatch. I couldn't find any docs on the older quickbooks java sdk so I could be wrong.
I got it resolved by installing MyEclipse 11 (Version: 2013 SR1) on another system (CentOS) while the previous system was Linux Fedora. Although I am still using jboss 7, however it works now. I don't know exactly how it got working, so no clue is available.
This is due to the .jar you are using. If you check the QuickBooks SDK, you might be able to see that there are some jars with the name followed by "with dependencies".
For example ipp-v3-java-devkit-2.3.2-jar-with-dependencies.jar. If both this and the jar with out dependencies (in this case ipp-v3-java-devkit-2.3.2.jar) are present at the same time, you might get the above error.
Remove the latter from the class path and you should be good to go.

Restlet client interface class

Restlet looks cool, but Im sorry, I'm just banging my head all day due to lack of documentation on a simple client.
I've managed to crib some useful stuff from
http://restlet.org/learn/guide/2.1/core/resource/client
But there is just nothing that actually works as a full download (which would be nice). For example is the Customer here a pojo only ? or must it implement Serializable (I think it must).
My specific issue is as follows:
I have some code which makes a call to a URL and gets back this:
{"result":"success","data":{"last_local":{"value":"889.66000","value_int":"88966000","display":"$889.66","display_short":"$889.66","currency":"USD"},"last":{"value":"889.66000","value_int":"88966000","display":"$889.66","display_short":"$889.66","currency":"USD"},"last_orig":{"value":"889.66000","value_int":"88966000","display":"$889.66","display_short":"$889.66","currency":"USD"},"last_all":{"value":"889.66000","value_int":"88966000","display":"$889.66","display_short":"$889.66","currency":"USD"},"buy":{"value":"889.00000","value_int":"88900000","display":"$889.00","display_short":"$889.00","currency":"USD"},"sell":{"value":"889.66000","value_int":"88966000","display":"$889.66","display_short":"$889.66","currency":"USD"},"now":"1388846889233438"}}
The bit I'm struggling with, is the MAGIC that happens as follows:
ClientResource cr = new ClientResource(….); // fine
IDataStruct resource = cr.wrap(IDataStruct.class); // <---- Magic here, but fine at Runtime.
if(cr.getResponse().getStatus().isSuccess()) // fine
{
PriceObject price = resource.retrieve();//<--- get to this line but then everything blows up because no converter is found. I can't use Jackson because GAE does not like it
}
The question is, what should the IDataStruct interface look like ??
Will.
Customer in the example is indeed a POJO. Depending on the converter you would use, you can make it serializable or not. BTW, Jackson should work on GAE, which issue did you encounter exactly?
IDataStruct should be a Java interface annotated with Restlet API annotations such as #Get, #Post, etc.
Regarding the user guide, you can find the edited version in GitHub, where I just fixed some of the broken links (will be published soon on Restlet.org):
https://github.com/restlet/restlet-sites/blob/master/modules/org.restlet/learn/guide/2.1/introduction/first-steps/first-client.md

ServiceLoader issue in WebLogic12c

I have been trying to refactor our Activiti implementation into using CDI but ran into a number of problems. I've spent way too much time trying to resolve this already, but I just can't let it go...I think I've pinned the problem down now, setting up a clean structured war without involving Activiti and have been able to reproduce what I think is the main problem.
Basically I have jar1 and jar2, both CDI enabled by including META-INF/beans.xml. Both jars specify a class in META-INF/services/test.TheTest pointing to implementations local to respective jar. jar1 depends on jar2. Also, both jars point to an implementation of javax.enterprise.inject.spi.Extension, triggering the scenario. In each implementation of Extension, I have a method like:
public void afterDeploymentValidation(
#Observes AfterDeploymentValidation event, BeanManager beanManager) {
System.out.println("In jar1 extension");
ServiceLoader<TheTest> loader = ServiceLoader.load(TheTest.class);
Iterator<TheTest> serviceIterator = loader.iterator();
List<TheTest> discoveredLookups = new ArrayList<TheTest>();
while (serviceIterator.hasNext()) {
TheTest serviceInstance = (TheTest) serviceIterator.next();
discoveredLookups.add(serviceInstance);
System.out.println(serviceInstance.getClass().getName());
}
}
Now, my problem is that the ServiceLoader does not see any implementations in either case when running WebLogic12c. The same code works perfectly fine in both Jboss 7.1.1 and Glassfish , listing both implementations of the test.TheTest interface.
Is it fair to assume that this is indeed a problem in WebLogic 12c or am I doing something wrong? Please bare in mind that I am simply trying to emulate the production setup we use when incorporating Activiti.
Regards,
/Petter
There is a Classloader Analysis Tool provided with WLS, have you seen if this will help with the diagnosis of your issue.
You can access this tool by going to ip:port/wls-cat/index.jsp
Where port will be the port of the managed server where your application is deployed.