New answers tagged

5

Don't think yet about the tool that you are going to use. You can do DI without an IoC Container. First point: Mark Seemann has a very good book about DI in .Net Second: composition root. Make sure that the whole set up is done on the entry point of the project. Rest of your code should know about injections, not about any tool that is being used. Third:...


0

Correct approach is to use constructor injection, if you use What I'm thinking about is that I can create a few specific factories which will contain logic of creating objects for a few specific class types. Basically a static class with a method invoking Ninject Get() method of a static kernel instance in this class. then you end up with ...


-1

You can have the best of both worlds by overriding the behavior HtmlEncode. This is accomplished by overriding the HttpEncoder class like so: using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Web; using System.Web.Util; using System.Text; using System.IO; /// <summary> ...


0

The best advice is to not use HttpUtility.HtmlEncode. The problem is that this returns a string, which means that the type system cannot catch encoding mismatches. The best solution is to have an HTML struct that represents strictly and only HTML, and then use instances of this to represent HTML, rather than strings. Then the compiler can assure you that ...


2

Assuming you will call HttpUtility.HtmlEncoded() from your extension method (otherwise it's a no-no) and also that you will use a meaningful name to your method (otherwise you will just make code less clear). Given: string someText = "This is some text"; Let's compare: string htmlEncoded1 = someText.ToHtmlEncodedString(); string htmlEncoded2 = ...


0

being able to save and restore that sequence from disk Are we talking about a file system, here, or a "DB", as in your posting's Title? In the file system, just write your list items into a file. They will be stored in the order you want them and you can read them back in the same order. Notepad does something remarkably similar. If you did want to ...


5

Polymorphism with no shared interface will ONLY let you store objects in the same (strongly typed) container, not actually DO anything. You can't disptach method calls or anything like that. In your specific example, I think composition would be more appropriate, no? You already have an abstraction for a specific point in 2d space, so why woudn't you reuse ...


2

The two subclasses does not have any interface in common, so why you do you want to have them inherit from a common class in the first place? The Location class does not provide you any benefit as far as I can tell. To me it would seem to more logical to have the Line contain two Point's.


0

The headline asks about the CLR, the Common Language Runtime. The question text itself is about the CIL, The Common Intermediate Language. They are different things! CLR. Yes, any .net developer needs a good understanding of the CLR. CIL. No, a typical developer does not need to know CIL in any depth. If you need to write a compiler or perform some low ...


10

My observation is that WebForms is on the decline. There is a good reason for that. Having used WebForms extensively in the past, it's difficult to do something outside the box. In addition to the learning aspx controls and their proper usage, there is a lot of technical minutiae to learn about the page life cycle when going beyond basics. And in the end, ...


2

I've worked on a number of microservice projects. Inevitably companies have taken the route because their big DB approach cant scale any further. Here are my experiences/recomenations. Org. One solution per microservice. nuget packages for shared libs Development. larger teams 5-6 devs one area of functionality at a time. Refactor into a interfaced service....


4

The first form creates an array of integers. The second form creates an array of something. The major difference is that the first variant gives you, the developer, the explicit indication of the type of objects stored in the collection. This indication will help both at the moment of writing code if you use an IDE with IntelliSense, and at the moment when ...


1

You wrote Some applications have use for values to be remembered between sessions well, that is true whenever you have to persist data would be to create a file of a specific format (XML, JSON, ini, or something else) in the user's data directory and use it for such values. [...] One example is the timestamp of the last time a certain function ...


1

Properties.Settings are stored for the user on the machine. If you want the settings to be common to all users and/or all machines, this method would not do. You also may want to have input parameters for the application that steer its behavior rather than preferences, and have several sets of them ready to be used in different senarios. For this, Properties....


1

If your create a fourth lib and use project references, you will not get the desired result, that way a consumer of that lib will still need to reference all the libs individually. However, at least you can put the initialization code in that fourth lib. Your first alternative will most probably work well when you still keep each of the current libs in its ...


0

Do not create tokens in the business layer unless your company's business is security. It can either be its own project or part of the web api. The web api is, after all, the trust border for the application, and the tokens are likely translated (by web api) into user objects for your other layers. Ideally, you shouldn't handling this in your own code at ...


0

I have seen the approach of adding a default constructor that calls the parameterized constructor with default instances, i.e. "poor man's dependency injection". public OrderWriter() : this(new TextFileWriter()) { } The regular code path calls the default constructor, whereas the unit test initializes using the custom constructor. If anyone could ...


2

Most databases have tables that store schema information about tables that are being maintained. For example, in SQL Server: SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = @Table ORDER BY COLUMN_NAME Will get you a list of columns for a particular table. However, in your case, I would just ...


0

Pretty sure they always iterate in order If not use the Ordinal There is a DataType if you have a standard format for a type Dictionary is not going to be the easiest syntax but it will be the fastest Dictionary<string, int> dicColMap = new Dictionary<sting, int>(); foreach(DataColumn column in table.Columns) { Console.WriteLine(column....


1

I'd go to simple inheritance, but maybe you can group some classes in subsets like visual studio does. For instance, you got Control as the parent class with the core properties and behavior for all controls: caption, location, etc.; in the other hand there's a class that inherits Control that acts as a parent for SaveFileDialog and OpenFileDialog, since ...


1

You could have separate classes for each queue and inject those, instead of injecting the factory. Your design as described here does not need a factory beyond the IoC-container as the type of queue can be determined at compile-time. Classes that need access to the queue can simply request an IUploadedDocsQueue or IRequestedDocsQueue as constructor ...


0

Looks largely ok to me. There's nothing to say that a factory should only have one method for creation. The Gang-of-Four book specifically has examples in which a factory creates families of objects (I think the example were GUI widgets for different platforms e.g. Motif windows/buttons vs. OpenLook windows/buttons or similar). From the book (and the link ...


1

Microsoft is probably the best "person" to ask this. If you expect some rhyme or reason to their versioning scheme, you're not going to find much on the Internet; they've changed their numbering scheme at least once. However... It appears that the build number is part of a strategy of allowing the version to be encoded in a single DWORD in the registry, ...


7

As Anders says, its partly about performance and partly about locking down poorly-thought designs down to reduce the scope of trouble caused later by people blindly inheriting things that were not designed to be inherited. Performance seems obvious - while most methods wont be noticed on modern hardware, a virtual getter might cause quite a noticeable hit, ...


6

There's two elements to your question, so I'll try and address them in turn: Why aren't .NET methods virtual by default? Inheritance, in practice, has many problems. So if it is to be used as part of a design, then it should be carefully considered. By making methods non-virtual by default, the theory is that it encourages the developer to think about ...



Top 50 recent answers are included