static-class

Access or get Autofac Container inside a static class

雨燕双飞 提交于 2019-12-04 07:13:24
I need to get or access to my IoC container in a static class. This is my (simplified) scenario: I register dependencies for ASP .net Web Api in a Startup class (but also I do this for MVC or WCF. I have a DependecyResolver project, but for simplicity, consider the following code) // Web Api project - Startup.cs public void Configuration(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); var builder = new ContainerBuilder(); // ... Omited for clarity builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies()) .AsClosedTypesOf(typeof(IHandle<>))

Load static class in appdomain

限于喜欢 提交于 2019-11-30 22:34:00
I'm met with a big problem in C# AppDomain. I need to load a static class in a .dll file and execute its method: When I try to load them by Assembly.LoadFrom("XXXXX") // (XXXXX is the full path of dll) the .dll will not be unload automatically or programmatically. When I try to load them in AppDomain like adapterDomain = AppDomain.CreateDomain("AdapterDomain"); (a)adapterDomain.CreateInstanceFrom(this.AdapterFilePath, this.AdapterFullName); (b)adapterAssembly=adapterDomain.Load(AssemblyName.GetAssemblyName(this.AdapterFilePath)); If I use method (a), because the target class is a static one,

Should you avoid static classes?

自闭症网瘾萝莉.ら 提交于 2019-11-30 13:44:10
问题 are static classes considered bad practice? I read an article about this a couple days ago (can't find it, sorry) which basically said that having static classes (especially those 'helper' classes) are typically a sign of bad code. Is this correct, and if so, for what reasons? 回答1: The abuse of static classes can be considered bad practice. But so can the abuse of any language feature. I make no distinction between a non-static class with only static methods and a static class. They are

Should you avoid static classes?

孤街醉人 提交于 2019-11-30 08:01:59
are static classes considered bad practice? I read an article about this a couple days ago (can't find it, sorry) which basically said that having static classes (especially those 'helper' classes) are typically a sign of bad code. Is this correct, and if so, for what reasons? The abuse of static classes can be considered bad practice. But so can the abuse of any language feature. I make no distinction between a non-static class with only static methods and a static class. They are effectively the same thing, except that static classes allow the compiler to enforce the developers intent (no

Inner class in interface vs in class

别说谁变了你拦得住时间么 提交于 2019-11-28 04:22:42
What is the difference between these two innerclass declarations? Also comment on advantages/disadvantages? case A: class within a class. public class Levels { static public class Items { public String value; public String path; public String getValue() { return value;} } } and case B: class within interface. public interface Levels{ public class Items { public String value; public String path; public String getValue() { return value;} } } Made correction: to placement of getvalue method. further info: I am able to instantiate Items class in both cases A and B in another class that does not

Inner class in interface vs in class

送分小仙女□ 提交于 2019-11-27 05:22:06
问题 What is the difference between these two innerclass declarations? Also comment on advantages/disadvantages? case A: class within a class. public class Levels { static public class Items { public String value; public String path; public String getValue() { return value;} } } and case B: class within interface. public interface Levels{ public class Items { public String value; public String path; public String getValue() { return value;} } } Made correction: to placement of getvalue method.

@autowired in static classes

假如想象 提交于 2019-11-27 04:14:37
This is an Spring MVC project with Hibernate. I'm, trying to make a Logger class that, is responsible for inputting logs into database. Other classes just call proper methods with some attributes and this class should do all magic. By nature it should be a class with static methods, but that causes problems with autowiering dao object. public class StatisticLogger { @Autowired static Dao dao; public static void AddLoginEvent(LogStatisticBean user){ //TODO code it god damn it } public static void AddDocumentEvent(LogStatisticBean user, Document document, DocumentActionFlags actionPerformed){ /

@autowired in static classes

最后都变了- 提交于 2019-11-26 11:06:45
问题 This is an Spring MVC project with Hibernate. I\'m, trying to make a Logger class that, is responsible for inputting logs into database. Other classes just call proper methods with some attributes and this class should do all magic. By nature it should be a class with static methods, but that causes problems with autowiering dao object. public class StatisticLogger { @Autowired static Dao dao; public static void AddLoginEvent(LogStatisticBean user){ //TODO code it god damn it } public static

Why are you not able to declare a class as static in Java?

不想你离开。 提交于 2019-11-26 00:45:17
问题 Why are you not able to declare a class as static in Java? 回答1: Only nested classes can be static. By doing so you can use the nested class without having an instance of the outer class. class OuterClass{ public static class StaticNestedClass{ } public class InnerClass{ } public InnerClass getAnInnerClass(){ return new InnerClass(); } //This method doesn't work public static InnerClass getAnInnerClassStatically(){ return new InnerClass(); } } class OtherClass{ //Use of a static nested class: