logo
down
shadow

How do you initialize application state at startup and access it from controllers in MVC 6?


How do you initialize application state at startup and access it from controllers in MVC 6?

By : user2956328
Date : November 22 2020, 10:54 AM
I think the issue was by ths following , Use dependency injection. Register a singleton service that has your data, and then use constructor injection on your controllers to acquire the service instance.
First, define a service. A service can really be any class or interface.
code :
public class MyConfigService {
    // declare some properties/methods/whatever on here
}
services.AddSingleton<MyConfigService>();
public MyController : Controller {
    public MyController(MyConfigService myService) {
        // do something with the service (read some data from it, store it in a private field/property, etc.
    }
}


Share : facebook icon twitter icon
Initialize Java EE Application Cache on Startup

Initialize Java EE Application Cache on Startup


By : Tshwaragano Morakabe
Date : March 29 2020, 07:55 AM
hop of those help? Assuming you have a webapp, the easiest thing to do is use a ServletContextListener to initialize the app on startup.
http://java.sun.com/javaee/6/docs/api/javax/servlet/ServletContextListener.html
code :
public class MyListener implements ServletContextListener {

   public void contextInitialized(ServletContextEvent sce) {
      // initialize cache here
   }

   public void contextDestroyed(ServletContextEvent sce) {
      // shut down logic?
   }
}
<listener>
   <listener-class>com.x.MyListener</listener-class>
</listener>
Jersey app-run initialization code on startup to initialize application

Jersey app-run initialization code on startup to initialize application


By : user3533453
Date : March 29 2020, 07:55 AM
I wish this help you Not sure what you mean by "Jersey resources are loaded before", but if you want to really plug in into Jersey init process.. Jersey has several "monitoring" plugin points (not widely advertised or documented) and what I'm going to describe is being called after initialization of AbstractResourceModel - so right after app startup.
Try this:
code :
@Provider
public class Listener implements AbstractResourceModelListener {

    @Override
    public void onLoaded(AbstractResourceModelContext modelContext) {
        System.out.println("##### resource model initiated");
    }
}
Can the startup/splash screen be changed depending upon the state of the application upon startup?

Can the startup/splash screen be changed depending upon the state of the application upon startup?


By : nlcharan
Date : March 29 2020, 07:55 AM
like below fixes the issue No, it is not currently possible. You cannot access the Default.png (or whatever you've named it instead) from your app to update it.
If it were me, I would set the startup screen to the one that is appropriate long term. You could also theoretically update your registration screen to be a bit closer to the look and feel of the main app screen, so it isn't so far off visually.
Access Servlet which is initialize during webserver startup

Access Servlet which is initialize during webserver startup


By : raranak
Date : March 29 2020, 07:55 AM
seems to work fine Is there any specific reason why Configuration is a Servlet? If this class's sole purpose is to read properties to be used later and it is not serving any requests by itself, it shouldn't be a Servlet.
There are two ways to do these configuration classes.
Initialize multiple connection pools once for all application at startup

Initialize multiple connection pools once for all application at startup


By : freddy
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Finally, it turned out that there was a problem with Context. I had to use env Context:
code :
Context envCtx = (Context) ctx.lookup("java:comp/env");
public final class DataBaseHandler {

  public static final class DataSources {
    public static final DataSource DB1;
    public static final DataSource DB2;
    public static final DataSource DB3;
    public static final DataSource DB4;

    static {
      try {
        Context ctx = new InitialContext();
        Context envCtx = (Context) ctx.lookup("java:comp/env");
        DB1 = (DataSource) envCtx.lookup("jdbc/DB1");
        DB2 = (DataSource) envCtx.lookup("jdbc/DB2");
        DB3 = (DataSource) envCtx.lookup("jdbc/DB3");
        DB4 = (DataSource) envCtx.lookup("jdbc/DB4");
      } 
      catch (NamingException ex) {
        throw new ExceptionInInitializerError("DataSource is not initialized");
      }
    }
  }
}
Related Posts Related Posts :
  • Looking for simplest option to render Razor cshtml pages in a console application without any web server
  • Evaluating variables at a specific time in Modelica
  • When I run the Application, only "web" engine is running in GlassFish. "webservices" is not started
  • How To Set MIME Type Of Google Drive File
  • Remove Missing Values in Weka
  • Reloading a UICollectionView using reloadData method returns immediately before reloading data
  • carrot2 - can I cluster documents from a folder?
  • StreamSocket has no Close Implementation in C#
  • Rails, Foundation 4, Respond.js not working properly in IE8
  • How can i create imagesurface from cairo xlib's Graphics Context using cairo and x11 Api's?
  • CKEditor "overflow: scroll" on parent causes toolbar to freeze at initial position
  • Differences between components and controls in ENYO
  • Photoshop making isometric?
  • Does Intel IPP 8.0 support in-place operations?
  • What is Object dictionary in CANOpen?
  • Example of orbBasic Indexed User Variables
  • convert to ABSOLUTE in logback
  • How to conditionally download file using p:fileDownload
  • Error on pod install
  • Set HTTP GET Parameters in Finagle
  • different attack that uses sql injection
  • How can I change my xampp username not as 'root'
  • AMQP Content header payload structure
  • Apache POI formula evaluation not working for Excel IF
  • How can I trace RESTEasy's dispatch?
  • Map Freezes on iOS 7 with Google Maps SDK 1.4
  • Comparing lists, is the subset list within the first list
  • Non-ascii character highlight in Sublime Text 2
  • Installing Magit in Aquamacs
  • Receiving error - System.Net.Mail.SmtpException: 4.3.2 try again later
  • Coreaudio render callback in monotouch
  • The command 'yarn --v' also initiates 'yarn install' and installs packages automatically. Why is this happening?
  • save multiple matches in a list (grep or awk)
  • Can a number register be used in a groff request?
  • Mapping FAQ with RASA for large dataset (2000+)
  • Fragment not receiving LiveData updates after remove + add
  • FitText.js makes text bigger rather than smaller
  • ARM - Implementing stack with load/store multiple register values
  • How to check if a ChromeCast Session is already in progress
  • ngForm inside a Carousel Slide in UI Bootstrap not working
  • Clearing attributes in Tritium
  • "vagrant up" failing: Vagrant VM failed to remain in the running state
  • ftsearch returning empty docs
  • What are the advantages of setting "hive.exec.parallel" to false in Hive ?
  • Creating a root certificate in FiddlerCore
  • How to access app.config in a blueprint?
  • DB2 RECORDSET table name converted to uppercase
  • Resizing the superview according to the subviews
  • IExpress - Disable Compression
  • Getting InvalidProtocolBufferException while running oozie job
  • What are the differences between Play run and start?
  • How can I share props in ReasonReact?
  • Task.Delay is skipped
  • Parsley.js Password Confirm doesn‘t work
  • How to get all registred 'browser:resource' in Plone
  • Overriding page_list controller inside a package in Concrete5.6.1.2
  • Robolectric 2.x - dependent jars are downloading while running the tests
  • Setting Flyout to Main Frame Navigation(Windows 8.1 app store)
  • Build project - Nuget Error
  • How to recover admin password for SonarQube
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org