I am getting to grips with Windows Azure. I usually use NInject as my IoC container in web apps. However, when trying to use it within an Azure web role I get a security exception (something to do with reflection permission).
Has anyone used other IoC with Azure and had succcess?
I just have been prototyping with Azure services today (not Web role, though).
Autofac IoC Container for .NET has worked in this scenario.
From Ninject google group: http://groups.google.com/group/ninject/browse_thread/thread/8d5a0aff853c6b4f/20209877f8db179a?show_docid=20209877f8db179a
If you set the kernel option UseReflectionBasedInjection, Ninject will work
in Azure (as well as other partial trust environments):
var options = new KernelOptions
{
UseReflectionBasedInjection = true
};
var kernel = new StandardKernel(options, new ModuleA(), new ModuleB(), ...);
Related
We have an asp.net core Web API and registering our EF DB context like so
services
.AddDbContext<SiteDbContext>((serviceProvider, opt) =>
{
opt
.UseNpgsql(options.Site)
.UseInternalServiceProvider(serviceProvider)
;
})
The DB Context calls DbContextOptionsBuilder.UseLoggerFactory which fails.
Looking at this doco https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbcontextoptionsbuilder.useloggerfactory?view=efcore-5.0
It is mentioned that you can't do what I just did above and suggested to "In this case, the ILoggerFactory should be configured directly in that service provider."
My question is how is that specifically done? to configure directly in that service provider.
From the docs (emphasis mine):
Sets the IServiceProvider that the context should resolve all of its services from. EF will create and manage a service provider if none is specified.
The service provider must contain all the services required by Entity Framework (and the database being used). The Entity Framework services can be registered using an extension method on IServiceCollection. For example, the Microsoft SQL Server provider includes an AddEntityFrameworkSqlServer() method to add the required services.
You shouldn't try to replace the internal service provider with the app-level service provider unless you register every single internal service EF core needs.
If you actually need to set the logger factory, there's an easier way to configure it. Use an overload that gives you an IServiceProvider:
services.AddDbContext<AppDbContext>((provider, options) =>
{
var loggerFactory = provider.GetRequiredService<ILoggerFactory>();
options
.UseNpgsql(/* ... */)
.UseLoggerFactory(loggerFactory);
});
I know how to create the app service plan . I need to be able to deploy the code and the configuration.
Yes, it is possible to create a function app using Azure Management Fluent Api.
You can use the below ifunctionapp interface to create the function app using fluent api's:
public interface IFunctionApp :
Microsoft.Azure.Management.AppService.Fluent.IWebAppBase,
Microsoft.Azure.Management.ResourceManager.Fluent.Core.IBeta,
Microsoft.Azure.Management.ResourceManager.Fluent.Core.IGroupableResource<Microsoft.Azure.Management.AppService.Fluent.IAppServiceManager,Microsoft.Azure.Management.AppService.Fluent.Models.SiteInner>,
Microsoft.Azure.Management.ResourceManager.Fluent.Core.IHasInner<Microsoft.Azure.Management.AppService.Fluent.Models.SiteInner>,
Microsoft.Azure.Management.ResourceManager.Fluent.Core.IHasManager<Microsoft.Azure.Management.AppService.Fluent.IAppServiceManager>,
Microsoft.Azure.Management.ResourceManager.Fluent.Core.ResourceActions.IRefreshable<Microsoft.Azure.Management.AppService.Fluent.IFunctionApp>,
Microsoft.Azure.Management.ResourceManager.Fluent.Core.ResourceActions.IUpdatable<Microsoft.Azure.Management.AppService.Fluent.FunctionApp.Update.IUpdate>
using the "IWithPackageUri.WithPackageUri(String) Method" by specifing the zipped packed to deploy
public Microsoft.Azure.Management.AppService.Fluent.WebDeployment.Definition.IWithExecute WithPackageUri (string packageUri);
i have an ServiceFabric StatefulService with Remoting inside a ServiceFabric Solution which also contains a Stateless WebApi and want to use Application Insights for monitoring this service. The WebApi uses already AI and it works fine.
I tried this in a dummy project an everything works fine with configuring AI in the constructor of the service:
public ReliableService(StatefulServiceContext context) : base(context)
{
var instrumentationKey = "myIKey";
TelemetryConfiguration.Active.TelemetryInitializers.Add(
FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(this.Context)
);
_telemetryClient = new Microsoft.ApplicationInsights.TelemetryClient { InstrumentationKey = instrumentationKey };
TelemetryConfiguration.Active.InstrumentationKey = instrumentationKey;
TelemetryConfiguration.Active.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
TelemetryConfiguration.Active.TelemetryInitializers.Add(new HttpDependenciesParsingTelemetryInitializer());
new DependencyTrackingTelemetryModule().Initialize(TelemetryConfiguration.Active);
new ServiceRemotingRequestTrackingTelemetryModule().Initialize(TelemetryConfiguration.Active);
new ServiceRemotingDependencyTrackingTelemetryModule().Initialize(TelemetryConfiguration.Active);
}
But when I copy the same code to the existing project only the WebApi sends telemetry data to AI, nothing from the statefull service.
Any idea what i'm doing wrong? The documentations are not really helpful for me, there is not full example of using AI in a statefull service with remoting.
Thank you for your answers!
You will need this package https://github.com/Microsoft/ApplicationInsights-ServiceFabric to make it work with Service Remoting.
The configuration story is very different depends on your project type, e.g, console app, Asp.Net, or Asp.Net Core. If you're on Asp.Net/Asp.Net core project, the configuration story will be better than what you have done in the dummy project.
Here is some examples that could be helpful https://github.com/yantang-msft/service-fabric-application-insights-example
I'm am trying to connect to a Service Fabric application using the ServiceProxy class like so:
return ServiceProxy.Create<ISomeService>(
new Uri("fabric:/SomeService.App/ISomeService"),
new ServicePartitionKey(0));
When I do this from a .Net Framework application everything works fine.
However, when I try this from a .Net Core application I get the following error:
InnerException = {System.Fabric.FabricInvalidAddressException: NamedEndpoint 'V2Listener' not found in the address '{"Endpoints":{"":"..."}}' for partition '...')
I'm assuming this has something to do with V2 remoting, but I can't figure out what exactly it is in the .Net Core project that is defaulting it to use V2 instead of V1.
Is there a way I can force it to use V1 - I'm not in a position to upgrade the target service to V2 at the moment.
All applications involved are using Service Fabric version 6.1.480
Only relevant documentation I can find is Service Fabric Reliable Services Communication Remoting and it hasn't helped me find a solution.
You can only use SF Remoting V2 in .Net Core.
Remoting V1 is supported using Full Framework only. (I agree that the documentation should specify this.)
See this link
In Jboss 5.1 the Profile Service does what the Deployment Service was doing in Jboss 4.x.In Jboss 4.x I was using the Deployment Service to create a datasource "on-the-fly" and I was wondering if I could do the same thing using the Profile Service (since Deployment Service doesn't exist any more in Jboss 5.x).
Does anyone know a practical guid on using ProfileService?
Thank you ,
Regards.
I don't know of any guide but I can provide you with my experience using the Profile Service and a few links to JBoss wiki pages on this topic. I'd like to post more links but the spam protection doesn't allow me to post more than two, but you should easily find the other pages in the wiki on the ProfileService. Don't be suprised in case you don't find much, there isn't more.
ProfileService ManagementView
http://community.jboss.org/wiki/ProfileServiceManagementView
ProfileService DeploymentTemplates
http://community.jboss.org/wiki/ProfileServiceDeploymentTemplates
There you'll find usefull information about the ProfileService but no detailed information is available in the jboss wiki as far as I can tell.
In order to create Datasources on the fly you can use the DeploymentTemplates (also for creating message queues and topics) The last link provides you with information on how to use the templates but not with all the template names and their properties. You can list them programatically though.
// Get all Templates
for(String template : mgtView.getTemplateNames())
{
System.out.println("=========================================");
System.out.println("Listing properties for template: "+template);
DeploymentTemplateInfo info = mgtView.getTemplate(template);
for(String prop : info.getProperties().keySet())
System.out.println("- "+prop);
}
In order to get the ManagementView (mgtView) from an external java programm you can use something similiar to this:
// set security policy
System.setProperty("java.security.policy", "<path_to_policy_file>");
System.setSecurityManager( new RMISecurityManager() ) ;
// set initial context properties
Hashtable<String, String> env = new Hashtable<String, String>();
env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
env.put("java.naming.provider.url","jnp://localhost:1099");
env.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
ctx = new InitialContext(env);
// login to JBoss
SecurityClient client = SecurityClientFactory.getSecurityClient();
client.setSimple("admin", "admin");
client.login();
// get ProfileService and ViewManager
ProfileService ps = (ProfileService) ctx.lookup("ProfileService");
mgtView = ps.getViewManager();
What you want to get is the Java Naming Conext (InitialContext). In order to do that you'll need a security policy (you can use the java.policy file which is located in JBOSS_HOME/server/SERVER_DIR/conf/),security manager and environment properties to get the context. The java.naming.provider.url specifies the location of the JBoss naming service (default port is 1099).
Usually you would have to authenticate at this point which is done with the SecurityClient.
Finally you can use the context to grap the ProfileService.
At this point most of the anoying stuff is done und you can start playing around.
getViewManager() returns the ViewManager with which you can create datasources on the fly and getDeploymentManager() will give you the DeploymentManager with which you can deploy, undeploy, start, stop applications and other deployments.
The libraries you'll need to do that are located in
JBOSS_HOME/client
JBOSS_HOME/lib
JBOSS_HOME/common/lib
I've read several times that including the jbossall-client.jar in the client directory should be enough but that's actually not true. You need libraries from all three directories as far as I can tell (couldn't do it without referencing all of them at least). I haven't figured out which exact jars you need though...
IMPORTANT: The ProfileService in Jboss 5 Community Edition has some bugs though which got fixed in JBoss 6. I'd either suggest using a newer JBoss version or the Enterprise Edition.