Can't find neither UseLog4Net nor FromThisAssembly using Castle.Core

140 views
Skip to first unread message

Maurício Fedatto

unread,
Jul 1, 2018, 4:41:00 AM7/1/18
to Castle Project Users

I'm trying to learn more about .Net Core and Castle dependency injection and inversion of control, but I just can't find neither UseLog4Net in LoggingFacility, while implementing my CompositionRoot, nor FromThisAssembly in Classes while implementing my installers.


What am I doing wrong?


CompositionRoot.cs

using Castle.Facilities.Logging;
using Castle.Windsor;

namespace PitchulaBeerNBurger.POS.CrossCuttingConcerns.DependencyInjection
{
    public class CompositionRoot
    {
        public virtual void ComposeApplication(IWindsorContainer container)
        {
            container.AddFacility<LoggingFacility>(f => f.UseLog4Net());

            container.Install(
                new Installers.CrossCuttingConcerns(),
                new Installers.Persistence(),
                new Installers.Domain(),
                new Installers.Business()
            );
        }
    }
}


DomainInstaller.css

using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;

namespace PitchulaBeerNBurger.POS.CrossCuttingConcerns.Installers
{
    public class Domain : IWindsorInstaller
    {
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(Classes.FromThisAssembly()
                                      .Where(type => type.Name.EndsWith("Factory"))
                                      .LifestyleSingleton());
        }
    }
}


NuGet packages installed:

Castle.Core.4.3.1
Castle.Core-log4net.4.3.1
Castle.LoggingFacility

Jonathon Rossi

unread,
Jul 1, 2018, 4:51:33 AM7/1/18
to castle-pro...@googlegroups.com
LoggingFacility.UseLog4Net isn't available in Windsor with .NET Standard builds, Castle Core only just added support for log4net and NLog for .NET Standard builds in Castle Core 4.3.0 (2018-06-07) because those 2 libraries now have .NET Standard builds. You'll note though that we deprecated UseLog4Net even on .NET Framework this year and you should now use LogUsing<T> directly instead, see the docs: https://github.com/castleproject/Windsor/blob/master/docs/logging-facility.md.

The .NET Standard build of Windsor doesn't have Classes.FromThisAssembly because .NET Standard 1.3 doesn't expose Assembly.GetCallingAssembly(), so you can use Classes.FromAssembly(typeof(Domain)) or some other type to scope the call.

Most of the limitations of the .NET Standard build are documented in Windsor's readme: https://github.com/castleproject/Windsor

Jono
--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to castle-project-u...@googlegroups.com.
To post to this group, send email to castle-pro...@googlegroups.com.
Visit this group at https://groups.google.com/group/castle-project-users.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages