Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Unity DI config implementation question

Unity DI config implementation question

Scheduled Pinned Locked Moved C#
questiongame-devbusiness
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 3919049
    wrote on last edited by
    #1

    I am implementing Unity in a business app for the first time. Here is some sample code to implement logging DI with Unity: UnityContainer uc = new UnityContainer(); uc.RegisterType<ILogger, FileLogger>(); ILogger logger = uc.Resolve<ILogger>(); logger.Write(); One way to implement this in an app would be to put this code in an AppConfig.cs class and implement GetLogger as a singleton. What's your preferred way to implement Unity in this scenario?

    R 1 Reply Last reply
    0
    • M Member 3919049

      I am implementing Unity in a business app for the first time. Here is some sample code to implement logging DI with Unity: UnityContainer uc = new UnityContainer(); uc.RegisterType<ILogger, FileLogger>(); ILogger logger = uc.Resolve<ILogger>(); logger.Write(); One way to implement this in an app would be to put this code in an AppConfig.cs class and implement GetLogger as a singleton. What's your preferred way to implement Unity in this scenario?

      R Offline
      R Offline
      Ravi Sant
      wrote on last edited by
      #2

      I think Singleton is best way of implementing. Why would you choose other way? any specific requirements? :)

      M 1 Reply Last reply
      0
      • R Ravi Sant

        I think Singleton is best way of implementing. Why would you choose other way? any specific requirements? :)

        M Offline
        M Offline
        Member 3919049
        wrote on last edited by
        #3

        Ok - so to implement this as a singleton how would you envision the solution structure? For example, would you see a singleton class in its own class library with a namespace like: "MyCompany.MyDivision.MyApp.DI"? With the singleton class named something like "DIManager"? Then I suppose that every library that needed the DI info would need to add a reference to the custom DI class library? Is this correct?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups