You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In your Main program method, build up your container and register services using the Autofac extensions. This will attach service registrations from the container and the ServiceRuntime. Dispose of the container at app shutdown.
usingSystem;usingSystem.Diagnostics;usingSystem.Reflection;usingSystem.Threading;usingAutofac;usingAutofac.Integration.ServiceFabric;namespaceDemoService{publicstaticclassProgram{privatestaticvoidMain(){try{// The ServiceManifest.xml file defines one or more service type names.// Registering a service maps a service type name to a .NET type.// When Service Fabric creates an instance of this service type,// an instance of the class is created in this host process.// Start with the trusty old container builder.varbuilder=newContainerBuilder();// Register any regular dependencies.builder.RegisterModule(newLoggerModule(ServiceEventSource.Current.Message));// Register the Autofac magic for Service Fabric support.builder.RegisterServiceFabricSupport();// Register a stateless service...builder.RegisterStatelessService<DemoStatelessService>("DemoStatelessServiceType");// ...and/or register a stateful service.// builder.RegisterStatefulService<DemoStatefulService>("DemoStatefulServiceType");using(builder.Build()){ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id,typeof(DemoStatelessService).Name);// Prevents this host process from terminating so services keep running.Thread.Sleep(Timeout.Infinite);}}catch(Exceptione){ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());throw;}}}}