what is difference between Serilog.Sinks.File and Serilog.Extensions.Logging.File packages in asp.net core?
When I tried to implement logging in asp.net core project with Serilog I found a quick example here which used Serilog.Sinks.File.
When I tried to implement the same in my project,the logger factory didnt have the extension AddFile().
But when I added another extension Serilog.Extensions.Logging.File I got the extension.
Are both extensions needed? or just Logging.File extension is enough?
What is the basic difference Sinks.File and Logging.File ?
In the link you provided, the example explicitly use Serilog.Extensions.Logging.File.
It is this extension that provide the AddFile method to ILoggerFactory (via Extension Methods mecanisms in DotNet) :
Extension of Microsoft.Extensions.Logging.IloggerFactory
A quick look at the Nuget package definition of Serilog.Extensions.Logging.File indicates that it has a dependency on
Serilog.Sinks.RollingFile.
The latter extension itself has a dependency on Serilog.Sinks.File.
So, Serilog.Extensions.Logging.File extends ILoggerFactory, providing the AddFile() method. That method uses the RollingFile class (as seen in the source code).
Related
Hello I have many many projects in many solutions and all use Ninject as IoC container. Common libraries have Ninject modules, the applications (like console application) usually have modules too and combine the modules in one StandardKernel. Now I have to change all common libraries to Autofac.
Let's say I make modifications and use Autofac (by defining Autofac modules) in a project named A (common library). A is referenced in project B (a console application) which still uses Ninject. Let's assume that for now I do not want to modify project B too much and I want to leave Ninject there.
It is possible to use Autofac modules from project A when in the end I use Ninject's StandardKernel in the "final" project B?
To the best of my knowledge there is no adapter that just "converts" one IoC format to the other. I don't think Ninject supports Microsoft.Extensions.DependencyInjection format registrations, either, so trying to use the IServiceCollection from there as a bridge also won't work.
Unfortunately, I think you're stuck. You'll have to do it all at once. Sorry.
Sources has comment that TryAdd version do not adds service if it is already registered in IServiceCollection. But docs doesn't mention this method.
When it should be used?
Typically if you have a library with dependencies you would create an extension method of IServiceCollection that the consumer of you library would call from startup to wire up the default dependencies.
.TryAdd is useful inside your extension method when only one implementation of an interface should be used. Then if someone wants to override a default implementation they can register it before calling your extension method and since their implementation is registered first the TryAdd won't add anything.
If .Add is used in your extension method, one can still override the default implementation by registering their implementation after the call to your extension method. But in this case there are still multiple implementations registered so one could take a dependency on IEnumerable of IFoo and get all the implementations that have been registered. But if they take a dependency on IFoo they get just the default one ie the last one added.
Apache Camel comes with some relatively nice Groovy extensions so that you, for instance, can use closures with the Java DSL for defining routes.
Most, if not all, of the additional methods providing these extensions seem to be located in the class CamelGroovyMethods with static methods like
public static ProcessorDefinition<?> process(ProcessorDefinition<?> self,
Closure<?> processorLogic){/* implementation */}
How is the actual extension of the Camel java classes realised? Is CamelGroovyMethods used as a category somewhere, and if so, where is use(CamelGroovyMethods) called?
Just a guess, but as they are called extension methods they have probably been defined as such. Look in the jar, you should find a file called org.codehaus.groovy.runtime.ExtensionModule in META-INF/services. Have a look at Creating an extension module. I've used this technique myself and it works great except if you want to provide custom constructors, that requires an alternate mechanism.
...
Yep, found it ExtensionModule file in GitHub. They even provided the dsld file to assist with code completion in Eclipse.
I am currently experiencing a problem in my RCP application and wanted to ask, if someone stumbled over the same problem and can give me some valuable hints:
My RCP application allows plugins to provide implementations of a specific abstract class of my model (singleton) to extend my model during runtime via the update manager. I instantiate these classes via
extensionPointImplementation.createExecutableExtension(..)
after parsing the Eclipse registry. I can serialize the created instances using the default Java serialization API.
Now to the problem: The plugin trying to deserialize the objects cannot find the class implementations of the model extensions due to the fact, that there is no plugin dependency between the plugins. Nevertheless, it is not possible for me to create such a dependency which would make the idea of extending the model during runtime obsolete.
Is it possible to solve this problem by using the default Java serialization API or do I have to implement my own serialization (which parses the Eclipse registry and creates the instances via the line shown above if all necessary plugins are available, otherwise throw an exception) which might be based on the default Java serialization API (if possible I do not want to create the serialization completely by myself)?
Thanks.
You need to define a so called buddy policy.
In the bundle trying to instantiate the class add
Eclipse-BuddyPolicy: registered
to the manifest.mf.
In the bundle providing the class add
Eclipse-RegisterBuddy: <symbolic name of the bundle instantiating the class>
to the manifest.mf.
I want to use Ninject 2 on Castle Monorail. Searching on google, I found nothing about this.
I know there is Windsor which magically can integrate with Monorail, same as Ninject (with MVC extension) with ASP.NET MVC.
What steps I need to do to integrate DI framework (other than Windsor) with Monorail ? (any website link, tutorial, or code sample (preferably using Ninject 2))
fyi, I'm using C#
I don't think there's any documentation about this, but it's quite simple really. There's no magic to it. Since MonoRail and Windsor are completely separate projects, all you have to do is see how they integrate, then do the same for Ninject instead of Windsor.
More concretely, start with the MonoRailFacility which is the root of the integration. Instead of a Windsor facility, you'd use a Ninject module. Note it registers some components: IControllerTree, IWizardPageFactory, etc. The most important is IControllerFactory, which lets you resolve controllers from the container (in your case Ninject). You can leave all others as default for now (e.g. IFilterFactory/DefaultFilterFactory), and implement them as needed (i.e. when you need container control of filters).
Then call ServiceProviderLocator.Instance.AddLocatorStrategy(new NinjectAccessorStrategy()); where NinjectAccessorStrategy is an implementation of IAccessorStrategy which returns the Ninject kernel as a Castle.Core.IServiceProviderEx (which is nothing but a trivial extension of System.IServiceProvider). Since the Ninject kernel already implements IServiceProvider, it's trivial to write an adapter for IServiceProviderEx.