Angular 2 service startup - service

Is it possible to execute a service in angular 2 at startup?
bootstrap does not execute the service's contstructor.
And also, the injector is executing the service's contstructor each time there is an injection of the service in some component. is there a way to make the service singelton and make sure the ctor will run only once?

Add the service only to bootstrap and not to proiders in your components.
If you inject it in your AppComponent it will be instantiated and only once.
Adding the service to providers on a component creates a new instance for each component instance.

Bootstrap won't start the service, a consuming class that is injecting the service will. By listing it in bootstrap you will get singleton.
If you follow the convention of listing your injectable services (LogRepository) into the bootstrap, then all services will be singleton. (As in LogRepository)
bootstrap(TheApp, [HTTP_PROVIDERS,LogRepository]);
You can get more instances of injectable services if you list them as providers on a component but starting out, just list them in the bootstrap(). All singleton then.

Related

Is it possible to have a single frontend select between backends (defined dynamically)?

I am currently looking into deploying Traefik/Træfik on our service fabric cluster.
Basically I have a setup where I have any number of Applications (services), defined with a tenant name and each of these services is in fact a separate Web UI.
I am trying to figure out if I can configure a single frontend to target a backend so I don't have to define a new frontend each time I deploy a new UI app. Something like
[frontend.tenantui]
rule = "HostRegexp:localhost,{tenantName:[a-z]+}.example.com"
backend = "fabric:/WebApp/{tenantName}"
The idea is to have it such that I can just deploy new UI services without updating the frontend configuration.
I am currently using the Service Fabric provider for my backend services, but I am open to using the file provider or something else if that is required.
Update:
The servicemanifset contains labels, so as to let traefik create backends and frontends.
The labels are defined for one service, lets call it WebUI as an example. Now when I deploy an instance of WebUI it gets a label and traefik understands it.
Then I deploy ANOTHER instance with a DIFFERENT set of parameters, its still the WebUI service and it uses the same manifest, so it gets the same labels, and the same routing. But what I would really want was to let it have a label containing some sort of rule so I could route to the name of the service instance (determine at runtime not design time). Specifically I would like for the runtime part to be part of the domainname (thus the suggestion of a HostRegexp style rule)
I don't think it is possible to use the matched group from the HostRegexp to determine the backend.
A possibility would be to use the Property Manager API to dynamically set the frontend rule for the service instance after creating it. Also, see this for a complete example on using the API.

Issue in LightInject when getting service instance

I have integrated Light Inject in web api project. I am able to register service successfully in application_start in global.asax. I am using filter which needs to be registered as well in application_start in global.asax. Filter constructor have reference to the services registered however I am not able to get the service instance. Samplee code:
service registration is as below:
container.Register<ILogger, EPPSLogger>(GetLifetime());
filter registration needs instance of ILogger. Using below code:
config.Filters.Add(new EPPSAuthenticationFilter(
config.DependencyResolver.GetService<ILogger>(),
config.DependencyResolver.GetService<IAuthenticationSecrets>()));
gets the error when try to getService that lightinject module is not injected/registered. I cant upgrade to .net framework 4.5 or so.
Any help is highly appreciated.
Thanks

Service task node vs Domain Specific task node

What is the difference between a service task node and a domain specific node (custom work item) in jBPM?
Service task is defined in the bpmn2 specification and custom work items are the natural extension to your own domain requirements. From the implementation point of view the Service task allows you to interact with a Java Bean or a web service directly (just via configuration) and the Custom WorkItem requires you to define a connector (by implementing the WorkItemHandler interface) that you then need to add to the application class path.
Hope this helps.
Regards

WCF Data Service and Castle Windsor

I am trying to use the Castle Windsor with WCF Data Service. I have created an Entity Data Model say "Person" and added a WCF Data Service called "MyService.svc". This is then exposed through OData...
public class MyService: DataService<Person>
...
Now, the question is how do you go about resolving this using the Windsor Container after registering it? (I registered it through Global.asax). So when you make a request such as "http://localhost/MyService.svc", How do I go about resolving "MyService" instance? How and where could I intercept to provide an instance from Windsor container?
Have a look at these links. You have to add a few classes to hook in to the service factory. These examples are for Unity but I easily modified them for Castle Windsor:
http://initializecomponent.blogspot.com/2008/06/integrating-unity-with-wcf.html
http://initializecomponent.blogspot.com/2008/06/unity-wcf-and-iis.html

GWT GIN HOW TO: injection of remote services

The gin tutorial seems to imply that to inject remote services all you need to do is annotate with #Inject.
Do you you still need to define this in a module somewhere or is the point that you can just annotate with #Inject and it will work?
Gin has automatic support for remote services, as outlined in the tutorial you mentioned:
Every time Gin is asked to inject an asynchronous remote service, it will inject an instance retrieved through calling GWT.create on its regular remote service.
Therefore, it will 'just work'.